![]() |
Trying to limit a search to a single line...
I'm trying to catch strings that look like this:
Code:
<p class="calibre1">Dont be late for school, she called. [...]the regex search that I'm using Code:
>([^]*) |
Quote:
Code:
>([^]*?) |
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."
|
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>Code:
<p class="calibre1">“I have to go pick up Cindy.”</p> |
Try the following, works for that small sample.
Code:
(?<=[^p]>)([^]*?) |
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! |
(?<=[^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. |
Adding newlines in the character class will prohibit multiline matches in this case:
Code:
>([^\r\n]*)Code:
(?<=>)([^\r\n]*) |
Quote:
Thanks to both of you for gently continuing my reg-ex education! |
A pretty good site for learning regex stuff is here
|
Quote:
|
| All times are GMT -4. The time now is 07:54 PM. |
Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.