![]() |
#1 |
Zealot
![]() Posts: 134
Karma: 10
Join Date: Nov 2009
Location: Okotoks, AB, Canada
Device: iPad V-3
|
find: <i>(.*)</i>
I want to do a search that finds: <i>stuff and things</i> and there is more than one occurrence in the paragraph. I want to find them one at a time. I am using: <i>(.*)</i> as my search. I looked up the regex and can't seem to work out the code that will find each occurrence rather than span from the first <i> to the last </i> in the paragraph. The contents could be upper, lower, punctuation, numbers or white space, at random, thus the .*. TIA.
|
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
I think you need Regex's advanced features 'lookahead' and 'lookbehind' to do what you want. I'm by no means expert in this but I think it would be something like
Code:
(?<=<i>)(.*)(?=</i>) |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
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
|
I would have used:
Code:
<i>(.*?)</i> |
![]() |
![]() |
![]() |
#4 |
Zealot
![]() Posts: 134
Karma: 10
Join Date: Nov 2009
Location: Okotoks, AB, Canada
Device: iPad V-3
|
That worked perfectly. Thanks.
|
![]() |
![]() |
![]() |
#5 | |
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)
|
Quote:
![]() Useful feature, but not quite what the OP wanted. ![]() ... davidfor's solution works, kind of... but the proper way to do it looks like this: Code:
<i>((?:(?!</?i>).)*)</i>
... The difference between mine and davidfor's solutions is that, given the sample text: Code:
<i>sample <i>text</i></i> This would matter a lot more if we were talking about a tag which is meant to be nested. ![]() Like spans. Which is why it is a very useful principle to know, although in this case you really can just make do with the easy solution. credits: I originally learned this trick here: https://stackoverflow.com/questions/.../406408#406408 Last edited by eschwartz; 03-15-2016 at 12:55 AM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Quote:
It would appear my Regex skills exceed my skills in basic reading/comprehension in my native language ![]() Sorry for any confusion, dicknskip. |
|
![]() |
![]() |
![]() |
#7 |
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)
|
|
![]() |
![]() |
![]() |
#8 | |
Well trained by Cats
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 30,949
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 are behind me, somewhere, way back there... (And I can't see the front-o-the-line ) |
|
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,251
Karma: 16539642
Join Date: Sep 2009
Location: UK
Device: ClaraHD, Forma, Libra2, Clara2E, LibraCol, PBTouchHD3
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#10 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Mar 2016
Device: none
|
I do a first pass like so:
Code:
text: <span class="italic">something</span> replace: <span class="italic">([^<]+)</span> with: <i>\1</i> result: <i>something</i> Code:
<span class="italic"><span class="bold">something</span></span> Code:
text: <span class="italic"><span class="bold">something</span></span> replace: <span class="italic">(.*?)</span> with: <i>\1</i> result: <i><span class="bold">something</span></i> replace: <span class="bold">(.*?)</span> with: <b>\1</b> result: <i><b>something</b></i> Code:
text: <a id="return_from_note_1"></a><a href="notes.html#note_1">see note 1</a> replace: <a id="([^"]+)"></a><a href="([^"]+)">(.*?)</a> with: <a id="\1" href="\2">\3</a> result: <a id="return_from_note_1" href="notes.html#note_1">see note 1</a> Code:
text: <i class="italic" style="margin:auto;padding:auto;font-size=1em;">something</i> replace: <i[^>]+>something</i> with: <i>\1</i> result: <i>something</i> |
![]() |
![]() |
![]() |
#11 |
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
|
I haven't hit the anchor one, but for the rest, I usually use Diap's Editing Toolbag. Much easier than trying to wrap my brain around the regex.
For the last one, why do you care about matching the close tags? Just fixing the opening should be enough. So: Code:
text: <i class="italic" style="margin:auto;padding:auto;font-size=1em;"> replace: <i[^>]+> with: <i> result: <i> |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find/Replace Won't Find | Rand Brittain | Sigil | 7 | 09-24-2011 04:35 AM |
Get Find to find an exact phrase | evwool | Amazon Kindle | 4 | 08-16-2011 08:47 AM |
Find this NOT that | Danger | Sigil | 5 | 12-27-2010 03:13 PM |
Help me find this if you can... | Spanner | Reading Recommendations | 3 | 10-12-2010 12:38 PM |