-3

Regex for multi line search that should select text "abc" which comes before the text "xyz" and should not select anything except "abc"

suppose if the text is as below,

    aaaabbbb
    abc
     abc
 lmn xyz

the regex should match only the text abc in 3rd line just above last line

adarsha bv
  • 43
  • 2
  • 13
  • And where is your code? Have You even tried anything? – malutki5200 Dec 08 '16 at 10:25
  • Aha, you want to match the shortest window between the value you need and some text after it. You need to use a tempered greedy token. [This answer of mine](http://stackoverflow.com/a/40556433/3832970) (for an ICU regex flavor that is similar to PCRE) can throw some light on how this is done. Please try on your own based on that, and come back if you fail to get the result you need. – Wiktor Stribiżew Dec 08 '16 at 10:27
  • No, this scenario is for multi line search – adarsha bv Dec 08 '16 at 10:40

1 Answers1

0

Could you please try the following:

/.*(abc).*xyz/s

Please note the s option which makes this work across multiple lines by just using .* to skip both regular characters and new lines

Miro
  • 1
  • 2