02-01-2012, 09:05 PM | #1 |
Zealot
Posts: 107
Karma: 1000
Join Date: Mar 2011
Device: Kindle
|
non greedy regEx
In a string like this:
<p class="sgc-9"><a id="v45">The Seven Factors of the Awakened mind—</a><a href="../Text/mainnotes.xhtml#p37-1" id="n151"><sup>151</sup></a><br /> I want to be able to search for this part:<a id="v45">The Seven Factors of the Awakened mind—</a> I have tried using <a id="(.+)">(.*?)</a> <a id="(.+)">.+?</a> <a id="(.+)">(.+)?</a> and <a id="(.+)">(.+)</a> But it keeps finding this: <a id="v45">The Seven Factors of the Awakened mind—</a><a href="../Text/mainnotes.xhtml#p37-1" id="n151"><sup>151</sup></a> I know it has something to do with greedyness, but I can't figure it out. Didn't there used to be a minimal matching option in a tick box?The project is to replace the string with this <span id="\1">\2</span> because it seems that ADE renders everything in a <a> tag with an underline. |
02-01-2012, 09:16 PM | #2 |
Well trained by Cats
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Have you tried putting the non-greedy after the </a>?
That is the anchor close you are looking for. |
02-01-2012, 09:34 PM | #3 |
Zealot
Posts: 114
Karma: 5246
Join Date: Jul 2010
Device: none
|
Make it non-greedy everywhere:
<a id="(.+?)">(.*?)</a> You were using: Code:
<a id="(.+)"> Code:
<a id="v45">The Seven Factors of the Awakened mind—</a><a href="../Text/mainnotes.xhtml#p37-1" id="n151"> |
02-02-2012, 02:52 AM | #4 |
Evangelist
Posts: 416
Karma: 1045911
Join Date: Sep 2011
Location: Cape Town, South Africa
Device: Kindle 3
|
Just a reminder, there is an ungreedy flag. (?U).
|
02-02-2012, 03:06 AM | #5 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
|
02-02-2012, 05:36 AM | #6 |
Zealot
Posts: 107
Karma: 1000
Join Date: Mar 2011
Device: Kindle
|
|
02-02-2012, 05:39 AM | #7 |
Zealot
Posts: 107
Karma: 1000
Join Date: Mar 2011
Device: Kindle
|
|
02-02-2012, 06:12 AM | #8 | |
Zealot
Posts: 114
Karma: 5246
Join Date: Jul 2010
Device: none
|
Quote:
(?U)<a id="(.+)">(.+)</a> Serpentine posted a link to http://www.pcre.org/pcre.txt some time ago, it's an excellent source of info about PCRE. |
|
02-02-2012, 08:01 AM | #9 | |
Sigil & calibre developer
Posts: 2,488
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
|
Quote:
|
|
02-02-2012, 08:07 AM | #10 |
Zealot
Posts: 107
Karma: 1000
Join Date: Mar 2011
Device: Kindle
|
Again, thank you so much. I would have never figured it out on my own.
|
02-02-2012, 09:20 AM | #11 |
Well trained by Cats
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Is this greedy? | Sydney's Mom | General Discussions | 38 | 05-01-2011 03:38 PM |
Curse of the Greedy Copyright Holders | Steven Lake | Writers' Corner | 12 | 07-16-2010 06:47 PM |
Why are academic publishers so greedy? | random50 | Amazon Kindle | 13 | 02-02-2009 08:42 AM |
Just arrived in my greedy little hands.... | MWetherspoon | iRex | 1 | 03-03-2008 05:16 PM |
Greedy publisher cashes in with e-books | Colin Dunstan | News | 3 | 10-19-2005 03:26 PM |