![]() |
#1 |
Enthusiast
![]() Posts: 40
Karma: 10
Join Date: Jul 2015
Device: none
|
search & replace regular expression help
Hi, im looking for a regular expression to replace html rules without changing the content inside
so if a documents sets italic rules like <span class="italic">example one</span> <span class="italic">example two</span> <span class="italic">example three</span> am looking to change them to <i>example one</i> <i>example two</i> <i>example three</i> and only know a regex search parameter of <span class="italic">(.*?)</span> will find all instances, but dknow the replace equivalent to keep the content so assuming (.*?) is a search only parameter, whats the replace equivalent? Last edited by ni_c; 09-30-2015 at 02:28 AM. |
![]() |
![]() |
![]() |
#2 |
Interested in the matter
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 421
Karma: 426094
Join Date: Dec 2011
Location: Spain, south coast
Device: Pocketbook InkPad 3
|
Last edited by jbacelar; 09-30-2015 at 02:33 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
The parentheses form a capture group. You can reuse a capture group in a replacement, with an escaped number -- e.g. "\1" is the replacement for the first capture group.
This is more of a general regex question. You may want to bookmark http://regular-expressions.info (my favorite regex tutorial and reference) for quick reference instead of opening a thread here ![]() |
![]() |
![]() |
![]() |
#4 |
Perfectionist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 72
Karma: 12802
Join Date: Apr 2014
Device: none
|
Use <i>\1</i> for replace.
If covering multiple instances, go on with \2, \3 etc. Don't forget to turn the REGEX mode on. |
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() Posts: 40
Karma: 10
Join Date: Jul 2015
Device: none
|
thanks guys, had been confused by \1, last time i tried it, thought it just replaced everything with \1 for some reason. Works now, cheers, and thanks for the links, will read up on this
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Hah, we all piled on at once
![]() ![]() |
![]() |
![]() |
![]() |
#7 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Alternatively, you can use Diap's Editing Toolbag plugin. One of its functions is will do exactly this type of replacement.
|
![]() |
![]() |
![]() |
#8 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
|
Quote:
Here is an image showing you the specific settings you would use when using Diap's Editing Toolbag to go from "<i>Example</i>" to "<span class="italic">Example</span>": |
|
![]() |
![]() |
![]() |
#9 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,047
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:
you forgot to enclose the keep this part in a positional # matching ( ) You see the \3, then the were only 2 ( ) in the search where you replace was \1 foo \2 bar \3 |
|
![]() |
![]() |
![]() |
#10 |
Enthusiast
![]() Posts: 40
Karma: 10
Join Date: Jul 2015
Device: none
|
good stuff, will install that, see how it goes,
fwiw, the regex expression worked beautifully for what i actually wanted, converting destination footnote links into dual direction ones first gave footnotes ids like id="f-1", id="f-20" etc then converted destination placeholders like <a id="filepos789849"></a>20. using regex search expression "></a>(.*?) and replace expression " href="Chapter-01.html#f-\1">\1</a> resulting in <a id="filepos789849" href="Chapter-01.html#f-20.">20.</a> only needed to hit "replace and find" till the end of each chapter, change chapter numbers and continue, very quick, then just used normal mode to find ."> and replace with "> (to correct the ids) Last edited by ni_c; 09-30-2015 at 10:09 AM. |
![]() |
![]() |
![]() |
#11 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 31,047
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:
(\d+) Only a Integer Number (any amount digits) |
|
![]() |
![]() |
![]() |
#12 |
The Fumbler
![]() Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
|
Just search and replace
This is so simple you don't need a plugin to accomplish the task.
The only thing I would change, in order to avoid getting messed up with nested <span> tags, is to change the search string. Search: <span class="italic">(((?!<span).)*?)</span> Replace: <i>\1</i> Consider nested span tags: <span class="italic">Merry <span class="bold">Christmas </span>Everyone.</span> Search: <span class="italic">(.*?)</span> Replace: <i>\1</i> Would result in: <i>Merry <span class="bold">Christmas </i>Everyone.</span> The search/replace that I described does a look-ahead and would not select the span because it has a nested span. You would have to address the "span class="bold" first, then rerun the "span class="italic" to modify it. |
![]() |
![]() |
![]() |
#13 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Worth noting -- much as I am a fan and advocate of lookarounds, the plugin saves you from having to do that.
![]() For many people it's worth it for the convenience. |
![]() |
![]() |
![]() |
#14 |
Enthusiast
![]() Posts: 40
Karma: 10
Join Date: Jul 2015
Device: none
|
|
![]() |
![]() |
![]() |
#15 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Quote:
That DOES make a mess ![]() |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Search and replace question (regular expression) | Funslinger | Library Management | 2 | 06-21-2013 02:12 AM |
Help with regular expression search/replace | bfollowell | Sigil | 12 | 06-20-2013 07:36 PM |
How to obtain a new page for every chapter in regular expression (search/replace)? | Ravenik | Conversion | 2 | 05-24-2012 07:04 AM |
Search & Replace - Regular expression | oldbwl | Calibre | 2 | 01-09-2011 09:33 AM |
Find/Replace with regular expression | hydrolith | Sigil | 6 | 03-01-2010 08:42 PM |