need to add slashes

Kenneth Brody kenbrody at bestweb.net
Fri May 26 06:19:36 PDT 2006


Quoting Fairlight (Thu, 25 May 2006 22:50:52 -0400):

> When asked his whereabouts on Thu, May 25, 2006 at 08:49:38PM -0400,
> Kenneth Brody took the fifth, drank it, and then slurred:
> >
> > To add backslashes before apostrophes:
> >
> >     { {!" "!}@ | <"\">"'" | * }
>
> Okay, maybe I'm used to regular expressions and got in the wrong
> mindset, but what I tried testing earlier was:
>
> [ * ]<"\">"'"[ * ]
>
> Why doesn't that work?  :)
>
> Allow 0 or more characters, insert a backslash before any apostrophy,
> followed by zero or more characters.

No, that's not what it says:

   [ * ]    - Accept zero or one character.  (And, unless you're at EOF,
              it will always accept one character.)

   <"\">"'" - Insert a backslash if not there, and require an apostrophe.

   [ * ]    - Accept zero or one character.

You have no repeat loops.

The only thing acceptable here is a 2- or 3-character string with an
apostrophe in the second position, or a 3- or 4- character string with
backslash-apostrophe as the 2nd and 3rd characters.

> Why's it break on the "i" in "Mike's"?
>
> At least I had part of it right.  I just know somehow that RE thinking
> is screwing me up here.  But it's so much simpler:   s/'/\\'/g

Actually, regular expressions are only pattern matching, aren't they?
There isn't any "search and replace" in raw RE's.

> Done.  :)
>
> Okay, but back to my failing edit.  Why?

See above.

--
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list