Sublime Forum

Regex - Match first 5 lines from .txt (Non-empty)

#1

hello, I want to select (to match) the first 5 lines from a text, that are not empty.

How can I do this?

0 Likes

#2

\`(\s*^(\h*\S.*)){5}

http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

Edit: If you then want to select the lines individually (i.e. one selection for each line), do this:

  1. Split selection for each line with Selection → Split into Lines
  2. Open the find panel again
  3. Enable “In selection” search (a button on the left)
  4. Search for ^\h*\S.*
2 Likes

#3

Works fine, thank you !

0 Likes

#4

and can you tell me how can I select the last 5 lines?

I try something like this \S.*\z but will match only the last line

0 Likes

#6

((^\h*\S.*)\s*){5}\Z

I don’t know why, but neither \' nor \z seem to work. However, \Z does and is probably even better than the others.

0 Likes

#7

thanks a lot !

0 Likes