Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 12-16-2019, 06:17 AM   #1
Capricorn
Belgian Pommes Frites
Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.
 
Posts: 122
Karma: 35038
Join Date: Jan 2012
Device: Pocketbook Touch HD
Question on a conditional regex

I have been banging my head against the wall trying to figure out how conditional regexes work.

I have looked at http://rexegg.com/regex-conditionals.html to figure it out, but no luck so far. My understanding of regexes has not advanced enough that I can put this level of regexes together.

I want to have a conditional regex that says:

if "font-size: 1.0em;" then leave it as it is.
if font-size is anything else, then change it to font-size: xyz;

And I want to do the same for the font-family: xyz;

If possible, it should also work in text files, not just stylesheets, in case I find the occasional statement like:
<span style="font-size: 1.0em">XXXXX</span>

I would appreciate it if someone could help me with such a conditional regex.
.
Capricorn is offline   Reply With Quote
Old 12-16-2019, 07:51 AM   #2
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,347
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
My first impression is that conditionals are not supported under Sigil regex...but I have to admit, my regex-fu is not that strong... I'll be interest to see what the true experts have to say.

I would recommend not using styles within your html, you should use CSS files instead. <span style="font-size: 1.0em">XXXXX</span> is pure bloat.

"Structure in the HTML and style in the CSS"

Code:
CSS:
p        {font-size:1em}
p.double {font-size:2em}

HTML:
<p>Normal paragraph.</p>
<p>Normal paragraph.</p>
<p>Normal paragraph.</p>
<p class="double">Double font-size paragraph.</p>
<p>Normal paragraph.</p>
<p>Normal paragraph.</p>
Turtle91 is offline   Reply With Quote
Advert
Old 12-16-2019, 09:30 AM   #3
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,568
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Conditional subpatterns are supported in the PCRE version currently shipping with Sigil (PCRE 8.37).

https://www.pcre.org/original/doc/ht...ern.html#SEC21
DiapDealer is online now   Reply With Quote
Old 12-16-2019, 01:17 PM   #4
hobnail
Running with scissors
hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.hobnail ought to be getting tired of karma fortunes by now.
 
Posts: 1,586
Karma: 14328510
Join Date: Nov 2019
Device: none
Another way to do it would be to delete all of the "font-size: 1.0em;" and put a "font-size: 100%;" on the body tag. Then all of the unadorned p tags would use 1em (using CSS's cascade). That's assuming that the p tag isn't enclosed in something where the font size is a different size, for example, an h2. I've had books where they apparently didn't understand the cascade and put a 1em font size on almost everything.
hobnail is offline   Reply With Quote
Old 12-16-2019, 02:06 PM   #5
Capricorn
Belgian Pommes Frites
Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.
 
Posts: 122
Karma: 35038
Join Date: Jan 2012
Device: Pocketbook Touch HD
It is in the first place to change stuff in the stylesheet.

I understand using styles that way is not very good, but sometimes I can not be bothered to remove it, and leave it as is with minimal changes, when I feel like being lazy.
Capricorn is offline   Reply With Quote
Advert
Old 12-17-2019, 02:54 PM   #6
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,347
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
lol - I understand the need to be lazy sometimes. Although, with as much time as you put into figuring out conditional regex you could have replaced all those styles manually multiple times!
Turtle91 is offline   Reply With Quote
Old 12-18-2019, 01:06 AM   #7
Capricorn
Belgian Pommes Frites
Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.
 
Posts: 122
Karma: 35038
Join Date: Jan 2012
Device: Pocketbook Touch HD
LoL..................

My Regex Fu does not allow me to leave it alone, when I get it into my mind to try out new regex stuff.....lol....................

The basic problem is however bigger: my brain seems to know only one setting when it tries to understand regexes: "ultra slow". And sometimes, the regexes crash my brain and the setting changes to "zero". The true cause of these crashes has not yet been determined, despite deep debugging research. Ah yes, the universe is still full of mysteries............................

Lol,
Capricorn is offline   Reply With Quote
Old 12-18-2019, 10:14 AM   #8
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,568
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
You're not alone. I consider my Fu to be fair-to-middlin', and conditionals just make my head hurt. I've yet to find a use for them, myself. Lookarounds usually suffice for my needs. For instance, the following expression should ignore any form of "font-size: 1em". Regardless of whether it's:

font-size: 1em
font-size:1em
font-size: 1.0em
font-size:1.0em
font-size: 1.00em
font-size: 1em;

Code:
font-size:(?!\s*(1(\.0+)?em))\s*\K[^(;|})]*
You should then be able to replace the resulting match with any value you like.

I realize the regex conditional might have become your "white whale" at this point. If so, feel free to share any working solution you might eventually come up with.

Last edited by DiapDealer; 12-18-2019 at 10:21 AM.
DiapDealer is online now   Reply With Quote
Old 12-18-2019, 11:16 AM   #9
Capricorn
Belgian Pommes Frites
Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.
 
Posts: 122
Karma: 35038
Join Date: Jan 2012
Device: Pocketbook Touch HD
Oh yes, this is strong fu, this is nice fu. And I can use it in some other cases too. Perfect. Just what I needed.
Although lookarounds are still a bit of a mystery to me too, I at least understand what this regex does.
Many thanks.
Capricorn is offline   Reply With Quote
Old 12-18-2019, 11:39 AM   #10
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,568
Karma: 204127028
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Capricorn View Post
I at least understand what this regex does.
Well that's 100% of 85% of the battle.

EDIT: I actually had some extraneous parens in that expression. This one removes them (no change in the matching):
Code:
font-size:(?!\s*1(\.0+)?em)\s*\K[^(;|})]*

Last edited by DiapDealer; 12-18-2019 at 11:51 AM.
DiapDealer is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex question rolgiati Calibre 2 11-26-2017 01:58 PM
Regex question theaccountant Library Management 0 11-07-2016 02:29 PM
Regex question Hendrixxxxxxxx Sigil 17 01-06-2016 09:24 PM
Yet another regex question Jabby Sigil 8 01-30-2012 08:41 PM
Regex Question Archon Conversion 11 02-05-2011 10:13 AM


All times are GMT -4. The time now is 08:53 PM.


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