|
|
#1 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 286
Karma: 56788
Join Date: Jun 2011
Device: Kindle
|
Replacing code without replacing text?
First Case Every new paragraph is formatted as: Code:
<p class="calibre2"><span class="none">A Bunch of Text</span></p> Code:
<p class="calibre2"><span class="none">1.</span></p> Code:
<p class="calibre2"><span class="none">[0-9]+\.</span></p> Code:
<p class="calibre5"><span class="none">[0-9]+\.</span></p> Second Case In another book, there are random paragraph breaks mid-sentence. My solution to that would be to find all the new paragraphs that begin with a lower-case letter, and replace all the code between it and the previous paragraph. Again, finding the instances via reg-ex proved pretty intuitive: Code:
</p>[\s]+<p class="calibre2">[a-z] Looking over what I've written, I am humbled by how utterly inarticulate this all sounds, but if someone understands my gibberish, I'd be most grateful for any light you could shine on my problem.
__________________
When some wild-eyed, eight-foot-tall maniac grabs your neck, taps the back of your favorite head up against the barroom wall, and he looks you crooked in the eye and he asks you if you've paid your dues, well, you just stare that big sucker right back in the eye, and you remember what ol' Jack Burton always says at a time like that: "Have ya paid your dues, Jack?" "Yessir, the check is in the mail." Last edited by ElMiko; 11-30-2011 at 06:40 PM. |
|
|
|
|
|
#2 | |||
|
Staff to 4 Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,743
Karma: 2485850
Join Date: Aug 2009
Location: The (original) Silicon Valley, USA
Device: Galaxy Tab 2,Black Astak PEz, K4NT(now Wifes)
|
Quote:
Quote:
The red \1 is the found value inside the ( ) above changes the number to "[0-9]+\."! Second Case In another book, there are random paragraph breaks mid-sentence. My solution to that would be to find all the new paragraphs that begin with a lower-case letter, and replace all the code between it and the previous paragraph. Again, finding the instances via reg-ex proved pretty intuitive: Code:
</p>[\s]+<p class="calibre2">([a-z]) [/QUOTE] the replace is: (space)\1 Quote:
__________________
Using: Ubuntu(32 bit):Oneric,Precise and XPpro SP3, W7HP(64)- - Libre Office w/Writer2EPUB
|
|||
|
|
|
|
Enthusiast
|
|
|
|
#3 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 286
Karma: 56788
Join Date: Jun 2011
Device: Kindle
|
@theducks - Life. Saver. If I could impose on you for just one clarification which might help me understand the nature of my mistakes (and your solutions) better, i'd be even more grateful:
What was the significance of the parentheses? That is, how are they acting upon the expression in a way that would be distinct without them? Is it entirely so that the \1 knows what to refer to?
__________________
When some wild-eyed, eight-foot-tall maniac grabs your neck, taps the back of your favorite head up against the barroom wall, and he looks you crooked in the eye and he asks you if you've paid your dues, well, you just stare that big sucker right back in the eye, and you remember what ol' Jack Burton always says at a time like that: "Have ya paid your dues, Jack?" "Yessir, the check is in the mail." |
|
|
|
|
|
#4 | |
|
Staff to 4 Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,743
Karma: 2485850
Join Date: Aug 2009
Location: The (original) Silicon Valley, USA
Device: Galaxy Tab 2,Black Astak PEz, K4NT(now Wifes)
|
Quote:
\1 is the first \2 is the second and so on example: FN LN: (.+) (.+) want LN, FN \2, \1
__________________
Using: Ubuntu(32 bit):Oneric,Precise and XPpro SP3, W7HP(64)- - Libre Office w/Writer2EPUB
|
|
|
|
|
|
|
#5 |
|
Enthusiast
![]() ![]() ![]() ![]() Posts: 29
Karma: 300
Join Date: Oct 2011
Device: Sony PRS-650
|
I'm not very much experienced in regex but maybe I can throw some light. The parentheses are used to create a group, so that when replacing you can refer to it. That's the meaning of '\1': keep the original set of characters (the group) as it is.
You can use more than one group in the expression you want to match, for instance: <p class="calibre2"><span class="none">([0-9]+\.)</span>blablabla([0-9])</p> Then, when replacing, you can refer to each group using \1 and \2. Of course you can use as many groups as required depending on the complexity of the search. |
|
|
|
|
|
#6 |
|
Staff to 4 Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,743
Karma: 2485850
Join Date: Aug 2009
Location: The (original) Silicon Valley, USA
Device: Galaxy Tab 2,Black Astak PEz, K4NT(now Wifes)
|
Here is the Link to Manichean's tutorial that finally got REGEX through my thick skull
![]() http://www.mobileread.com/forums/sho...REGEX+Tutorial
__________________
Using: Ubuntu(32 bit):Oneric,Precise and XPpro SP3, W7HP(64)- - Libre Office w/Writer2EPUB
|
|
|
|
|
|
#7 |
|
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 286
Karma: 56788
Join Date: Jun 2011
Device: Kindle
|
@sellew - That's exactly the explanation I was looking for. Thank you for putting it so clearly! Manichean's tutorial is indeed incredibly helpful, but sometimes (oftentimes... most times...) I get lost anyway.
@ theducks - Thanks for the additional example. And sorry for being so obtuse sometimes (oftentimes... most times...)!
__________________
When some wild-eyed, eight-foot-tall maniac grabs your neck, taps the back of your favorite head up against the barroom wall, and he looks you crooked in the eye and he asks you if you've paid your dues, well, you just stare that big sucker right back in the eye, and you remember what ol' Jack Burton always says at a time like that: "Have ya paid your dues, Jack?" "Yessir, the check is in the mail." |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replacing Books on T1 | democrite | Sony Reader | 0 | 10-29-2011 06:24 PM |
| Replacing my Hanlin V3 | maddz | Which one should I buy? | 0 | 11-25-2010 04:14 AM |
| Replacing my new Kobo - again! | objectman | Kobo Reader | 7 | 09-20-2010 08:00 PM |
| Replacing the battery | AprilHare | Sony Reader | 12 | 04-29-2009 01:08 PM |
| Replacing ¬ | PieOPah | Workshop | 5 | 12-17-2008 04:25 PM |