Thread: Regex examples
View Single Post
Old 10-07-2023, 08:53 PM   #752
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,695
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
In my experience Minimal Match is working. It's just that the ? in an expression has the ability to negate/reverse the Minimal Match Setting (and vice-versa).

Consider the following content:

Code:
<p>This is a para.</p>
<p>This is a para.</p>
<p>This is a para.</p>
<p>This is a para.</p>
<p>This is a para.</p>
With Minimal Match unchecked (greedy) and dotAll checked, the following expression will grab multiple attribute-less paragraphs (as is intended):
Code:
<p>.*</p>
But if you leave the regex settings the same (Minimal Match unchecked and dotAll checked) and change the expression to:
Code:
<p>.*?</p>
It will be NON-greedy and only grab the first attribute-less paragraph. Again; as expected.

But this is where it gets tricky. If you leave the expression the same (<p>.*?</p>) and check Minimal Match, the search will then actually become greedy. If you remove the ? from the expression, and leave Minimal Match checked, the results will be non-greedy again.

Sigil's regex has always worked this way to my knowledge. So you have to be careful combining Minimal Match and ?. I've always used one or the other, but very rarely both both at the same time for that very reason.

In short: Using both Minimal Match and "?" can make an expression greedy.

You can also put my original content on one line and eliminate the dotAll option from the equation.
Code:
<p>This is a para.</p><p>This is a para.</p><p>This is a para.</p><p>This is a para.</p><p>This is a para.</p>

Last edited by DiapDealer; 10-07-2023 at 09:00 PM.
DiapDealer is offline   Reply With Quote