![]() |
#1 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 359
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Trying to limit a search to a single line...
I'm trying to catch strings that look like this:
Code:
<p class="calibre1">Don’t be late for school,” she called. [...] the regex search that I'm using Code:
>([^“]*)” |
![]() |
![]() |
![]() |
#2 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 657
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
|
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,352
Karma: 203720150
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
It depends on how you define a "line." If no line-break character is ever encountered, the regex Find doesn't really care if the code and/or text wraps around the screen several times... it still considers it all one "line."
|
![]() |
![]() |
![]() |
#4 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 359
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
I mean a line of code, not a line of text.
what's happening is that my search is returning the highlighted part of the following string: Code:
<p class="calibre1">“I have to go pick up Cindy.”</p>
<p class="calibre1">Well, don’t be late for school,” she called. [...]
Code:
<p class="calibre1">“I have to go pick up Cindy.”</p>
<p class="calibre1">Well, don’t be late for school,” she called. [...]
Last edited by ElMiko; 04-10-2012 at 06:16 PM. |
![]() |
![]() |
![]() |
#5 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 657
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
|
Try the following, works for that small sample.
Code:
(?<=[^p]>)([^“]*?)” |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 359
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Quote:
I tried referring to the reg-ex cheatsheet that (I believe) theducks recommended several months ago, but I couldn't really make heads or tales of it based on the descriptions. EDIT: aww heck, spoke too soon. If the preceding line of code doesn't contain dialogue, the expression captures multiple lines... I still would love an explanation for why the expression you provided DID work in that case. I might just be able to figure out how to extrapolate a comprehensive solution from that without bothering you guys any further! Last edited by ElMiko; 04-10-2012 at 07:31 PM. |
|
![]() |
![]() |
![]() |
#7 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 657
Karma: 64171
Join Date: Sep 2010
Location: Kent, England, Sol 3, ZZ9 plural Z Alpha
Device: Sony PRS-300, Kobo Aura HD, iPad (Marvin)
|
(?<=[^p]>)
The (?<= means that it looks for the next bit, but doesn't include it in the match, the [^p]> is looking for a '>' that isn't preceeded by a 'p' so it isn't matching on the the end paragraph tags, and the close ) is closing that group, then your actual search takes place. Hope that helps you work it out. Edit: If you give a larger sample and what it's messing up on and what you want matched, I'll have a look again. Last edited by Perkin; 04-10-2012 at 07:58 PM. |
![]() |
![]() |
![]() |
#8 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 54
Karma: 37363
Join Date: Aug 2011
Location: Istanbul
Device: EBW1150, Nook STR
|
Adding newlines in the character class will prohibit multiline matches in this case:
Code:
>([^“\r\n]*)” Code:
(?<=>)([^“\r\n]*)” |
![]() |
![]() |
![]() |
#9 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 359
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Quote:
Thanks to both of you for gently continuing my reg-ex education! |
|
![]() |
![]() |
![]() |
#11 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 359
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Quote:
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Single line scrolling... Is it possible? | maniac1181 | Amazon Kindle | 5 | 08-11-2011 12:19 AM |
line feed search | bobcdy | Sigil | 22 | 10-23-2010 09:21 PM |
PRS-600 Single Vertical Line issue | luluching | Sony Reader | 0 | 08-02-2010 09:36 PM |
single word wrapped onto a separate line on kindle (pdf to mobi) | shinew | Calibre | 2 | 03-21-2009 06:16 PM |
Google Book Search to search full-text books online | Bob Russell | Deals and Resources (No Self-Promotion or Affiliate Links) | 1 | 08-19-2006 12:13 PM |