Regex: Difference between revisions

From Andreida
(Created page with "=== non greedy === Imagine you have the following text: <nowiki><br />'Stupid ad'<br /><br />Real content<br /></nowiki> If you use the regular expression <nowiki><br />'St...")
 
(No difference)

Latest revision as of 20:18, 24 February 2023

non greedy

Imagine you have the following text:

<br />'Stupid ad'<br /><br />Real content<br />

If you use the regular expression

<br />'Stupid.*<br />

then you will match the complete text, not just the 'Stupid ad'. That is because '.' is greedy. If you want it to not be greedy, try:

<br />'Stupid.*?<br />

Now you should only match

<br />'Stupid ad'<br />

because you are using a non greedy search.