![]() |
#1 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 498
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
|
RegEx help on the replace side of things
I have this mostly figured out, I got it to work once (I'm pretty sure!) but can't seem to recreate it.
I want to change: <p><strong>text to change</strong></p> so it reads: <p><strong><font2>text to change</font2></strong></p> (<font2> is a tag I've created. It is defined, I've been using it for a few months without problem) The text between the tags should not change. It could have one word, it could have four words, it could have ten words. There is nothing certain. I can create a regex to find all the possibilities, but in the replace, no matter what I've tried, it only puts in the last word, ignoring all others there might be. Anyone have ideas? One I've tried is (I'm basic and it could probably be done simpler but there you go...): Find: <strong>([A-Za-z]+)</strong> Replace: <strong><font2>\1</font2></strong> I'm doing that off the top of my head and I feel I've forgotten something, but anyway, that's the gist of where I am. Thanks for the help! OH, I've checked different manuals and websites, but I think I'm not searching for the right terms and can't find anything to help me...or at least not that I understand. |
![]() |
![]() |
![]() |
#2 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 691
Karma: 3026110
Join Date: Dec 2008
Location: Lancashire, U.K.
Device: BeBook 1, BeBook Pure, Kobo Glo, (and HD),Energy Sistem EReader Pro +
|
The way you have constructed the "find" means that it will only find one word as you haven't included a space in the "find". Bear in mind also that you might need to include punctuation marks.
Try Find: <strong>(.*?)</strong> (Any character, any number of times but "non-greedy") It's a bit "brute force" so don't "replace all" until you are happy it doesn't catch anything you didn't intend. BobC |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 498
Karma: 32554
Join Date: May 2014
Location: Canada
Device: Kobo Sage
|
Well, it seems to work great! I'm not that good at most of the wildcards (can never figure out what the ? is used for. I can figure out the 'long' way, or I need it spelled out.
Unless I know for certain what will come up (and there is often other text with <strong> that I don't want changed) I don't usually use 'Replace All' so this works well for me. I only had one file to work with at the moment, but I'm waiting on a few more, so I'll have a better idea. Still, it seems to be what I'm looking for. Thank you so much! |
![]() |
![]() |
![]() |
#4 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,992
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:
Your original pattern only looked for Letters. A string with Anything else would have failed. Brute force can work or it can grab way too much ![]() IMHO try and include a 'limiter' (only appears in that string) in your pattern |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
regex search/replace - how to? | Alt68er | Sigil | 1 | 03-11-2014 08:53 PM |
Regex find and replace | SanatyrZeo | Sigil | 5 | 10-29-2012 07:03 AM |
regex replace??? | schuster | Conversion | 14 | 01-29-2011 09:02 AM |
RegEx find and replace | iblesq | Sigil | 1 | 01-10-2011 09:26 PM |
REGEX find and replace help please | potestus | Sigil | 13 | 09-18-2010 04:14 PM |