![]() |
#1 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Nov 2009
Location: Asturias
Device: Handlin
|
RegEx
Hi Bookworms.
I am having a problem with a RE expression and wonder if anyone could shed some light on the problem. I am trying to replace the div tags with h3 tags around the second headers of a book with lots of those, I think around 198 in total, bit tedious by hand. The headers are all upper-case and normally one space between words, this is my search string with minimal matching selected. <p class="western1">([^a-z]+[^¿][A-Z]+[\s].*)</p> This does select the headers but I can not figure out how to store the test contents of the headers. I seem to end up with only a part of the header, have tried to include up to 5 round brackets "(" and use the \1 to \5 to replace the contents but not luck. Would appreciate any help from the experts. ATB el.motar |
![]() |
![]() |
![]() |
#2 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,889
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
does <p class="western1"> appear on any other line? If so, what is the line just before the 'header"? Is it unique in relation. As always, do not post more than a few lines of copyrighted material without the authors (included) permission. |
|
![]() |
![]() |
![]() |
#3 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Nov 2009
Location: Asturias
Device: Handlin
|
Quote:
Thanks for your reply This is the actual paragraph. <p class="western3">CECILIA VOLANGES A SOFIA CARNAY EN EL CONVENTO DE URSULINAS DE . . .</p> I don remember the replacement string, as I have tried quite a few. Thanks. |
|
![]() |
![]() |
![]() |
#4 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,889
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
<p class="western3">(.+)</p> <h3 class="western3">\1</h3> I used H3, but you can use any. class="western3" is optional, usually I want some type of class as ADE does not center headers by default The above only is safe if western3 is used only on headers OR you step though the document manually Find Next, Replace or Find Next (to skip) |
|
![]() |
![]() |
![]() |
#5 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Nov 2009
Location: Asturias
Device: Handlin
|
Quote:
![]() The reason I was having problems with particular RE F and R is that there are two headers plus other paragraphs with the same tags, i.e. the one posted and this type. <p class="western3">Text text text text ....</p> I wanted to mark the headings CARTA as h2 tags and the others as h3 tags. The CARTA tags are easy, but once they are done, the only differentiation between these and the other paragraphs using the same tags is that these are all capital letters plus a space between the words. I was trying to select paragraphs which contain only capital letters, the RE expression posted does the selection but I could not work out the replacement string. Thanks for your time. ATB el.motar |
|
![]() |
![]() |
![]() |
#6 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,889
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
|
|
![]() |
![]() |
![]() |
#7 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,889
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
OK there is more to it
\0 puts the entire original inside the replace so pass 2 and 3 is needed to fix <h3 class="ct"><p class="western3">CECILIA VOLANGES A SOFIA CARNAY EN EL CONVENTO DE URSULINAS DE . . .</p></h3> BTW here is my search: <p class="western3">(([A-Z]+\s+){2,}.+)</p> and Replace <h3 class="ct">\0</h3> |
![]() |
![]() |
![]() |
#8 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Nov 2009
Location: Asturias
Device: Handlin
|
Quote:
This is great, save me a lot of time with my book. Worked a treat and is good to know about the "0". Thank you ATB el.motar |
|
![]() |
![]() |
![]() |
#9 |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,889
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
![]() |
![]() |
![]() |
#10 | |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Nov 2009
Location: Asturias
Device: Handlin
|
Quote:
But looking over your search I had it all wrong to start with. I guess that a bad search string would mean a worst replacement one. I am fairly new to RE so as they say it is hard at the beginning then it gets more complicated. BTW Could you tell me what the "{" bracket does? Thanks ATB el.motar |
|
![]() |
![]() |
![]() |
#11 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,889
Karma: 59840450
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
in this case 2 or more times (comma, no ending value This way it does not match I or A by themselves |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help me with regex please. | eVrajka | Library Management | 5 | 08-15-2011 12:17 PM |
regex help please | thevoiceofcheese | Calibre | 2 | 08-01-2011 11:27 PM |
Regex | Faster | Sigil | 2 | 04-24-2011 09:08 PM |
What a regex is | Worldwalker | Calibre | 20 | 05-10-2010 05:51 AM |
Help with a regex | A.T.E. | Calibre | 1 | 04-05-2010 07:50 AM |