Regex

From Andreida
Revision as of 20:18, 24 February 2023 by Andreas (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.