Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 02-23-2014, 04:10 AM   #1
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Question new regex question ( trailing 0 or 1 instance permultations

I could not see this covered in the regex sticky

I want to write a single find/replace that will zap all of

line-height:1.2;
line-height:1.3
line-height:1.2em;
line-height:1.2em
line-height: 1.2;
line-height: 1.3
line-height: 1.2em;
line-height: 1.2em

i.e. remove all fixed line heights in range 1-2 em from CSS.
NBthey may or may not have an explicit em & they may nor may not have a space after the first colon, and they may or may not have a trailing ;

I've got this far:
line-height:\s?1\.\d
I can't seem to also capture the last bits ?

update:
this works but it feels like a cheat, because it just grabs everything up to the next bit of white space. you could probably write a valid CSS with no white space between statements.
line-height:\s?1\.\d(.*)\s

Anyway, I'd like to learn the proper way to find and include zero or one instance of a given string

Last edited by cybmole; 02-23-2014 at 07:39 AM.
cybmole is offline   Reply With Quote
Old 02-23-2014, 05:00 AM   #2
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
How about this?

\s*line-height:\s*1(\.[0123]\d*)?(em)?\s*;

"line-height:" with any number of possible preceding spaces and any number of spaces after,
a "1",
possibly, a period, a 0, 1, 2 or 3, and any number of additional digits,
possibly, "em",
a semicolon preceded with any number of possible spaces.

That should catch "1em", "1.1333333", "1.2em", etc., but not not "1.5em" or "0"
Jellby is offline   Reply With Quote
Advert
Old 02-23-2014, 05:30 AM   #3
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
sounds great in theory but is not finding all the matches in my simple test file ?
e.g. it is skipping this line :
line-height:1.3
i think it needs a tweak to allow for no trailing semicolon ?

for testing, I created a blank stylesheet & put in

line-height:1.2;
line-height:1.3
line-height:1.2em;
line-height:1.2em
line-height: 1.9;
line-height: 1.4
line-height: 1.2em;
line-height: 1.2em
line-height:1.9;
line-height:1.4
line-height:1.2em;
line-height:1.2em

also your code works for the same reason as my cheat, it looks for a final mandated whitespace. if I remove that from your code then the find picks out only the bold part of
line-height:1.2em

the hard bit is getting the optional components to be included in what is captured, and allowing the final bit of the target to be an optional string

Last edited by cybmole; 02-23-2014 at 05:34 AM.
cybmole is offline   Reply With Quote
Old 02-23-2014, 06:15 AM   #4
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
The semicolon is only optional if it's the final element in a style. Maybe this?

\s*line-height:\s*1(\.[0123]\d*)?(em)?\s*[;}]

and check "multiline", or whatever there is to include newlines in \s. This, however, will not work if you want to remove everything (you should not remove the } ). You could preprocess the file and first replace every } with ;}, now every rule should be ended by a semicolon (and there will possibly be two consecutive semicolons in some cases, which you could remove afterwards).
Jellby is offline   Reply With Quote
Old 02-23-2014, 06:16 AM   #5
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,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
How about this quick and dirty regex: line-height:\s*1\.\d+[em;]*

Last edited by Doitsu; 02-23-2014 at 07:53 AM. Reason: Added final asterisk
Doitsu is offline   Reply With Quote
Advert
Old 02-23-2014, 07:00 AM   #6
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Originally Posted by Jellby View Post
The semicolon is only optional if it's the final element in a style. Maybe this?

\s*line-height:\s*1(\.[0123]\d*)?(em)?\s*[;}]

...
i know about the final element rule, but my test case examples are all from actual book syntax

your new code still skips this case
line-height:1.3
cybmole is offline   Reply With Quote
Old 02-23-2014, 07:02 AM   #7
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Originally Posted by Doitsu View Post
How about this quick and dirty regex: line-height:\s*1\.\d+[em;]
it stops too soon e.g. it captures only the bold below
line-height:1.2em;
cybmole is offline   Reply With Quote
Old 02-23-2014, 07:12 AM   #8
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,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by cybmole View Post
it stops too soon e.g. it captures only the bold below
line-height:1.2em;
What kind of editor do you use to test these regular expression?
The expression that I suggested will capture all test values in Notepad+, and, after adding an asterisk at the end, also with EmEdit.
Doitsu is offline   Reply With Quote
Old 02-23-2014, 07:38 AM   #9
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
i am testing with sigil !

I want to be able to use the solution in sigil

forum name is a clue
cybmole is offline   Reply With Quote
Old 02-23-2014, 07:43 AM   #10
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
Posts: 13,285
Karma: 78869092
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
Quote:
Originally Posted by cybmole View Post
it stops too soon e.g. it captures only the bold below
line-height:1.2em;
You're missing the * after the [em;]
PeterT is offline   Reply With Quote
Old 02-23-2014, 07:50 AM   #11
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,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by PeterT View Post
You're missing the * after the [em;]
You're right. I corrected my initial post. The following expression finds all test case strings:

line-height:\s*1\.\d+[em;]*
Doitsu is offline   Reply With Quote
Old 02-23-2014, 07:55 AM   #12
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by cybmole View Post
i know about the final element rule, but my test case examples are all from actual book syntax

your new code still skips this case
line-height:1.3
That's because that line is wrong, it's missing the semicolon. If it's in a real book, it would fail in ADE I guess.

Quote:
Originally Posted by Doitsu View Post
You're right. I corrected my initial post. The following expression finds all test case strings:

line-height:\s*1\.\d+[em;]*
It would also find 1.5mm

How about just ending with ";?" ?

\s*line-height:\s*1(\.[0123]\d*)?(em)?\s*;?
Jellby is offline   Reply With Quote
Old 02-23-2014, 08:28 AM   #13
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Originally Posted by PeterT View Post
You're missing the * after the [em;]
with the * added, it still stops here;
line-height:1.2em;
cybmole is offline   Reply With Quote
Old 02-23-2014, 08:30 AM   #14
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Quote:
Originally Posted by Jellby View Post
That's because that line is wrong, it's missing the semicolon. If it's in a real book, it would fail in ADE I guess.



It would also find 1.5mm

How about just ending with ";?" ?

\s*line-height:\s*1(\.[0123]\d*)?(em)?\s*;?
stops here
line-height:1.2em;

PS
ADE is quite happy for a real book to contain this in CSS - * I have seen it many times - no trailing ;

.calibre99
{
lineheight:1.2
}

but hey, I never claimed it was an easy puzzle

clearly " remove all fixed line heights from a given book" is not a trivial thing to automate

Last edited by cybmole; 02-23-2014 at 08:35 AM.
cybmole is offline   Reply With Quote
Old 02-23-2014, 02:12 PM   #15
Jellby
frumious Bandersnatch
Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.Jellby ought to be getting tired of karma fortunes by now.
 
Jellby's Avatar
 
Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
Quote:
Originally Posted by cybmole View Post
stops here
line-height:1.2em;
Hmm... I can't see why, but I have no Sigil to test.
Ah, well, I sort of see why... Isn't there an option for "greedy" matching?

Quote:
ADE is quite happy for a real book to contain this in CSS - * I have seen it many times - no trailing ;

.calibre99
{
lineheight:1.2
}
Yes, that's fine, and that should be catched by my previous suggestion (with multiline enabled), but this is not:

line-height:1.3
line-height:1.2em;

I understood that you were testing with that.
Jellby is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RegEx question (again) phossler Sigil 12 01-20-2013 02:37 PM
A regex question PatNY Sigil 30 06-03-2012 02:03 PM
Yet another regex question Jabby Sigil 8 01-30-2012 08:41 PM
Regex question and maybe some help crutledge Sigil 9 03-10-2011 04:37 PM
Regex Question Archon Conversion 11 02-05-2011 10:13 AM


All times are GMT -4. The time now is 10:41 AM.


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