This question already has an answer here:
这个问题在这里已有答案:
- What do 'lazy' and 'greedy' mean in the context of regular expressions? 11 answers
在正则表达式的上下文中,“懒惰”和“贪婪”是什么意思? 11个答案
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
我有一段文字,我需要匹配< latex和< / latex>之间的任何内容。但不是文本和等量的
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 \<\;(latex).+(latex)\>\;([^\s])
but it doesn't stop until the last </latex>
in the line.
我试过使用正则表达式\< \;(latex)。+(latex)\> \;([^ \ s])但它直到最后一行< / latex>才停止。
1 个解决方案
#1
0
You need to use a non-greedy match
你需要使用非贪婪的比赛
\<\;(latex).+?(latex)\>\;
#1
0
You need to use a non-greedy match
你需要使用非贪婪的比赛
\<\;(latex).+?(latex)\>\;