-1

Say you know the starting and ending lines of some section of text, but the chars in some lines and the number of lines between the starting and ending lines are variable, á la:

aaa
bbbb
cc
...
...
...
xx
yyy
Z

What quantifier do you use, something like:

aaa\nbbbb\ncc\n(.*\n)+xx\nyyy\nZ\n

to parse those sections of text as a group?

4 Answers4

0

You can use the s flag to match multilines texts, you can do it like: ~\w+ ~s. There is a similar question here: Javascript regex multiline flag doesn't work

Community
  • 1
  • 1
antoni
  • 5,001
  • 1
  • 35
  • 44
  • noticed that the exact content of the first "aaa", "bbbb", ... and last ..., "yyy", "Z" lines I know. Between those lines anything could appear in many lines. I mostly use regexps with eclipse, kate and office's writer – Joe Weinberg Jun 27 '16 at 17:41
0

If I understood correctly, you know that your text begins with aaa\nbbbb\ncc and ends with xx\nyyy\nZ\n. You could use aaa.+?bbbb.+?cc(.+?)xx.+?yyy.+?Z so that all operators are not greedy and you don't accidentally capture two groups at once. The text inbetween these groups would be in match group 1. You also need to turn the setting that causes dot to match new line on.

buld0zzr
  • 962
  • 5
  • 10
0

Try this:

aaa( |\n)bbbb( |\n)cc( |\n)( |\n){0,1}(.|\n)*xx( |\n)yyy( |\n)Z

( |\n) matches a space or a newline (so your starting and ending phrases can be split into different lines)

RegExr

Trev Davies
  • 391
  • 1
  • 10
0

At the end of the day what worked for me using Kate was:

( )+aaa\n( )+bbbb\n( )+cc\n(.|\n)*( )+xx\n( )+yyy\n( )+Z\n

using such regexps you can clear pages of quite a bit of junk.