0

I have a multi-line string

Some test
String
Here

I am using this regex pattern to find it (Some\s.*)(.|\n)* & replace it with \1\2

Instead of getting the same text back, I get

Some test e

Why isn't the second backreference working? Is there a better way to specify multiline in regex rather than (.|\n)*

PS : Using Sublime Text 2 on Windows

Update : I see my mistake after reading Jerry's answer.

user
  • 15,863
  • 15
  • 90
  • 110

1 Answers1

1
(.|\n)*

In this captured group, you'll get only the last match. You could try using this instead:

((?:.|\n)*)

Or if you want to match everything you could possibly use something like:

([\s\S]*)
Jerry
  • 67,172
  • 12
  • 92
  • 128
  • @buffer I can't seem to find a reference :( [this site](http://www.regular-expressions.info/refcapture.html) used to have a page describing it... But you can play around and see for yourself. Here's a [demo site](http://regex101.com/r/aL5wW5). I already put an example there and you can see the matched group is `d`, i.e. the last matched character. – Jerry Sep 23 '13 at 12:01
  • Took a moment to realize my obvious mistake after looking at your answer. Thanks. – user Sep 23 '13 at 16:29