0

I have a piece of text that I need to match anything between <latex and </latex> but not the text and an equivalent quantity of

Which given has the same divisor of <latex>5</latex> and an equivalent quantity of <latex>(5 + 2) \div 5</latex>?

I've tried with the regex \&lt\;(latex).+(latex)\&gt\;([^\s]) but it doesn't stop until the last </latex>in the line.

chepe263
  • 2,774
  • 22
  • 38
  • 1
    Quantifiers are greedy by default, this means that `.+` will take the largest possible substring. If available in your regex flavor, you need to use a non-greedy quantifier to get the smallest possible substring: `.+?` – Casimir et Hippolyte Jul 19 '17 at 23:47
  • If not available, you need to play with groups, character classes and alternations to describe what is allowed until `</latex>` – Casimir et Hippolyte Jul 19 '17 at 23:51

1 Answers1

0

You need to use a non-greedy match

\&lt\;(latex).+?(latex)\&gt\;
G5W
  • 36,531
  • 10
  • 47
  • 80