On Sat, Jan 28, 2012 at 09:24:41AM -0700, Warren Michelsen wrote:
> Is there a way in RegEx to say 'replace all of these except...'?
>
> In the following text:
>
> ('The Riddler's False Notion','87312','1966-04-28T00:00:00Z',null),
> ('Scat, Darn Catwoman','87251','1966-03-30T00:00:00Z',null),
> ('Surf's Up! Joker's Under!','97151','1966-12-28T00:00:00Z',null),
> ('I'll Be a Mummy's Uncle!','97091','1966-09-28T00:00:00Z',null),
> ('The Purr-Fect Crime','97091','1966-09-28T00:00:00Z',null),
> ('Tut's Case Is Shut','97091','1966-09-28T00:00:00Z',null),
> ('The Devil's Fingers','17031','1967-10-05T00:00:00Z',null);
>
> single-quote characters are used both as field delimiters and as apostrophes.
Tsk tsk. :)
> So, I'm wondering, in RegEx, is there a way to specify change ' to \' in
> all instances EXCEPT where adjacent to a comma or parentheses? That is, I
> know that I need not escape the single-quote characters in these
> situations:
> ('
> ','
> ',
>
> In those instances, the single-quote is a field delimiter and needed. All
> other instances are indeed apostrophes and need to be escaped.
>
> Can RegEx specify that?
Yes, you can use negative look-ahead and look-behind assertions:
Find
(?<![\(,\\])'(?![\),])
Replace
\\'
This matches a single quote that is not preceeded by [\(,\\] and not
followed by [\),]. I put \\ in there so you can, if you need to, run the
replace multiple times without overescaping the single quotes.
Ronald
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>