03-04-2012, 02:55 PM | #1 |
Gadget Freak
Posts: 1,169
Karma: 1043832
Join Date: Nov 2007
Location: US
Device: EE, Note 8
|
Regex
I have a book with 25 chapters where the 'Chapter' is in the same font size as the rest of the text; It looks like this;
<p class="calibre2"> CHAPTER ## </p>, where ## is the number 1 to 25. I have devised the following which finds all the chapter entries; <p class="calibre2">\sCHAPTER\s*\d*\s</p> I would like to replace it with something similar to; <h2 class="calibre3">CHAPTER ## </h2>, where ## is the number 1 to 25. But am unable to devise the correct sequence to save the ## from the search function and insert into the replace function. I read about back referencing including viewing "An introduction to regular expressions" and "Using the Search & Replace feature" without success. |
03-04-2012, 03:48 PM | #2 |
Enthusiast
Posts: 30
Karma: 752
Join Date: Nov 2010
Device: PB360
|
Use
Code:
<p class="calibre2">\sCHAPTER\s*(\d*)\s</p> Code:
<h2 class="calibre3">CHAPTER \1</h2> If you need more than one part of the searched text, surround each needed part with parentheses. In the replacement, use backslash and number where the number is the result of numbering the parentheses from left to right, starting with one. Last edited by JustForFun; 03-04-2012 at 03:51 PM. |
Advert | |
|
03-04-2012, 06:42 PM | #3 | |
Gadget Freak
Posts: 1,169
Karma: 1043832
Join Date: Nov 2007
Location: US
Device: EE, Note 8
|
@JustForFun
Quote:
If I had left a space after the \1 would it have matter? Assistance much appreciated! |
|
03-04-2012, 08:59 PM | #4 | |
Well trained by Cats
Posts: 29,782
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Chapter \1: \2 Where the \2 represents the sub-title match results ex. Chapter 2: The next Step |
|
03-04-2012, 10:24 PM | #5 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
On a side note - the heuristics detect chapters feature should do this for you automatically.
|
Advert | |
|
03-05-2012, 04:15 PM | #6 |
Gadget Freak
Posts: 1,169
Karma: 1043832
Join Date: Nov 2007
Location: US
Device: EE, Note 8
|
Thanks all.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
New help with a regex | txckie | Calibre | 2 | 08-29-2011 08:46 PM |
Help me with regex please. | eVrajka | Library Management | 5 | 08-15-2011 12:17 PM |
Regex | Faster | Sigil | 2 | 04-24-2011 09:08 PM |
What a regex is | Worldwalker | Calibre | 20 | 05-10-2010 05:51 AM |
Regex help... | Bobthebass | Workshop | 6 | 04-26-2009 03:54 PM |