Sublime Forum

Make Multiline Regex non greedy

#1

How can I make a multiline regex search ungreedy?

Example
(?s)<custom-attributes>.*</custom-attributes>
this will match an entire xml file with the first match of <custom… and the last match of </custom…
I just want it to match each occurrence.

0 Likes

#2

One way to achieve that would be to include the ? modifier on the .* construct in order to make it non-greedy:

(?s)<custom-attributes>.*?</custom-attributes>
1 Like

#3

genius. That worked perfectly.

0 Likes