How to multiline regex but stop after first match? -


i need match string has characteristics, think enabling /m flag breaking functionality.

what know:

  1. the string start , end quotation marks.
  2. the string have following words. "the", "fox", , "lazy".
  3. the string may have line break in middle.
  4. the string never have @ sign (used in regex statement)

my problem is, if have string twice in single block of text, returns once, matching between first quote mark , last quote mark required words in-between.

here regex:

/^"the[^@]*fox[^@]*lazy[^@]*"$/gim 

and regex101 example.

here understanding of statement. match string starts "the , there word fox , lazy (in order) somewhere before string ends ". ignore newlines , case-sensitivity.

the common answer limiting (.*?) doesn't work new lines. , putting [^@?]* doesn't work because adds ? list of things ignore.

so how can keep "match until ___" skipping until last instance while still being able ignore newlines?

this not duplicate of else can find because deals multi-line matching, , don't.

in case, quantifiers need non-greedy can use flag ungreedy: u.

/^"the[^@]*fox[^@]*lazy[^@]*"$/gimu 

example on regex101.


Comments