![]() |
#1 |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 541
Karma: 1152752
Join Date: Aug 2010
Location: Evansville, IN, USA
Device: Samsung Galaxy Tab 4 Nook & Samsung Galaxy Tab S 10.5
|
Need help coming up with another regular expression
I'm having trouble coming up with a regular expression that will work for what I need to do in Sigil. I downloaded a regex cheatsheet and have learned to use some very basic regular expressions but it seems like I run into trouble and have to learn something new every time I try something else.
Here's what I'm wanting to do and what I've tried. The following string is typical of a chapter subtitle and the first paragraph of a book I'm working on. Most chapters are identical to this except for the actual text of the subtitle. <p class="chaptersubtitle">An Army of Shadows</p> <p class="para"> I want to be able to search for this string, regardless of what the actual subtitle text is. I've tried: <p class="chaptersubtitle">[:print:]</p> <p class="calibre1"> and <p class="chaptersubtitle">[:alnum:]</p> <p class="calibre1"> but these don't seem to work. Do any of you regular expression gurus have any ideas? Any assistance would be greatly appreciated. Thanks. - Byron |
![]() |
![]() |
![]() |
#2 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,003
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Code:
<p class="chaptersubtitle">(.+)</p>\s+<p class="para"> ![]() Code:
<p class="chaptersubtitle">\1</p> <p class="para"> (I put it all back in my example) ![]() |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 541
Karma: 1152752
Join Date: Aug 2010
Location: Evansville, IN, USA
Device: Samsung Galaxy Tab 4 Nook & Samsung Galaxy Tab S 10.5
|
Thank you very much.
Well, this is certainly getting me closer to what I wanted than what I was trying. Now here's the problem. I only want to select the first chaptersubtitle class paragraph through the very next (first) normal paragraph tag. The expression you gave me selects pretty much ALL text, every single paragraph, character, whatever, through the last <p class="para"> tag. There may not be a way to have a regular expression do what I'm wanting from the behavior I'm seeing. Either way, I really appreciate your help. If you have any other ideas, let me know. Are you aware of any decent online resources for learning more about regular expressions? Thanks again. - Byron |
![]() |
![]() |
![]() |
#4 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,003
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#5 |
Fanatic
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 541
Karma: 1152752
Join Date: Aug 2010
Location: Evansville, IN, USA
Device: Samsung Galaxy Tab 4 Nook & Samsung Galaxy Tab S 10.5
|
Worked like a charm. Thanks again for your help. Now I need to go add this to my really, really big book of regex info...
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 697
Karma: 150000
Join Date: Feb 2010
Device: none
|
Keep in mind that Sigil's dialect of regex is most like the PERL dialect rather than the POSIX dialect, when you consult your cheat-sheet.
And I, for one, say Gottseidank for that. ![]() |
![]() |
![]() |
![]() |
#7 |
frumious Bandersnatch
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,546
Karma: 19001583
Join Date: Jan 2008
Location: Spaniard in Sweden
Device: Cybook Orizon, Kobo Aura
|
Sigil's regex is still Qt's QRegExp, isn't it? Then better refer to the correct doc, which I believe is: http://doc.qt.nokia.com/4.7/qregexp.html
|
![]() |
![]() |
![]() |
#8 | |
Created Sigil, FlightCrew
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,982
Karma: 350515
Join Date: Feb 2008
Device: Kobo Clara HD
|
Quote:
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Regular Expression Help | Azhad | Calibre | 86 | 09-27-2011 02:37 PM |
Regular Expression Help | iKarampa | Calibre | 13 | 12-15-2010 07:17 AM |
Regular expression help | krendk | Calibre | 4 | 12-04-2010 04:32 PM |
Regular Expression Help | smartmart | Calibre | 5 | 10-17-2010 05:19 AM |
Help with the regular expression | Dysonco | Calibre | 9 | 03-22-2010 10:45 PM |