Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 08-18-2024, 10:45 AM   #1
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Possible RegEx error in Sigil (minimal match being ignored)

Hello,

I'm trying to delete all 'span' tags with no content (i.e. <span blah blah>(nothing here)</span> by using the following RegEx (with minimal match enabled)

<span .*></span>

Here is some example text which shouldn't match anything

<hgroup><h2 class="CHAPTER" id="ch1"><span class="CN"><samp class="SANS_Futura_Std_Bold_Condensed_B_11">1</samp></span> <span class="CT"><samp class="SANS_Dogma_OT_Bold_B_11">WINDOWS FOUNDATIONAL CONCEPTS</samp></span></h2></hgroup>

As we can see, there are no span tags without content. Running this RegEx however matches the following text (as can be seen in the attached screenshot)
<span class="CN"><samp class="SANS_Futura_Std_Bold_Condensed_B_11">1</samp></span>

Is there anything I have missed, or is this indeed an error?

Rgds

Karl
Attached Thumbnails
Click image for larger version

Name:	regex error.png
Views:	74
Size:	22.3 KB
ID:	210250  
KarlG is offline   Reply With Quote
Old 08-18-2024, 12:29 PM   #2
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
The .* in your regular expression also matches other tags. The following expression should work:

Code:
<span[^>]*></span>
Doitsu is offline   Reply With Quote
Advert
Old 08-18-2024, 12:34 PM   #3
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by Doitsu View Post
The .* in your regular expression also matches other tags. The following expression should work:

Code:
<span[^>]*></span>
But surely when 'minimal match' is selected, the search should also stop with the first '>'.?
KarlG is offline   Reply With Quote
Old 08-18-2024, 02:02 PM   #4
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,045
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Nope. Minimal Match can't affect the inherent greediness of *.

At least I don't recall it doing so in the past.

Last edited by DiapDealer; 08-18-2024 at 02:07 PM.
DiapDealer is offline   Reply With Quote
Old 08-18-2024, 02:12 PM   #5
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by DiapDealer View Post
Nope. Minimal Match can't affect the inherent greediness of *.

At least I don't recall it doing so in the past.
Hmm, maybe confusion on my part here then.

So what IS 'minimal match' for then, and what's the option (if there is one) for a non-greedy RegEx in Sigil?
KarlG is offline   Reply With Quote
Advert
Old 08-18-2024, 02:29 PM   #6
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,045
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Doitsu's regex was an example of a non-greedy search. But let me do some investigation. I don't really use the Minimal Match option, so there could be a problem with it. I don't want to be too nasty in dismissing what might be a bug.
DiapDealer is offline   Reply With Quote
Old 08-18-2024, 02:38 PM   #7
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
And no the text search will only stop at the first ">" when a match is found, without a match it will continue to grow the search area until it finds the first match or none at all. That is what the "minimal match" flag means. It finds the minimal length match if one exists.

Last edited by KevinH; 08-21-2024 at 06:40 PM.
KevinH is offline   Reply With Quote
Old 08-18-2024, 03:40 PM   #8
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 40,631
Karma: 157444382
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Personally, I find it easier to use @DiapDealer's TagMechanic plugin for this type of task. Saves me from the issues when my fat fingers cause a typo,
DNSB is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
match an empty line with a regex? lumpynose Sigil 5 05-29-2019 04:03 AM
REGEX match everything before # JLius ePub 2 01-08-2017 05:25 PM
[Regex Search] Minimal match not possible? nqk Editor 7 12-24-2014 04:19 AM
how to have regex dot match any character including newline? gnychis Calibre 5 11-30-2010 07:35 PM
Need help with a conversion regex - can't match newline ereader123 Calibre 2 03-29-2010 11:58 AM


All times are GMT -4. The time now is 04:35 PM.


MobileRead.com is a privately owned, operated and funded community.