![]() |
#1 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
![]()
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. |
![]() |
![]() |
![]() |
#2 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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" |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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. |
![]() |
![]() |
![]() |
#4 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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). |
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
Quote:
your new code still skips this case line-height:1.3 |
|
![]() |
![]() |
![]() |
#7 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
|
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
The expression that I suggested will capture all test values in Notepad+, and, after adding an asterisk at the end, also with EmEdit. |
|
![]() |
![]() |
![]() |
#9 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 ![]() |
![]() |
![]() |
![]() |
#10 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,285
Karma: 78869092
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
|
![]() |
![]() |
![]() |
#11 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,680
Karma: 23983815
Join Date: Dec 2010
Device: Kindle PW2
|
|
![]() |
![]() |
![]() |
#12 | ||
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Quote:
Quote:
![]() How about just ending with ";?" ? \s*line-height:\s*1(\.[0123]\d*)?(em)?\s*;? |
||
![]() |
![]() |
![]() |
#13 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
|
![]() |
![]() |
![]() |
#14 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
|
Quote:
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. |
|
![]() |
![]() |
![]() |
#15 | |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,543
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
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:
line-height:1.3 line-height:1.2em; I understood that you were testing with that. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |