[ale] Regex question

Ed Cashin ecashin at noserose.net
Thu Nov 6 16:48:33 EST 2008


On Thu, Nov 6, 2008 at 1:22 PM, Chris Fowler
<cfowler at outpostsentinel.com> wrote:
> I'm using POSIX regular expressions to escape all the XML special
> characters from values in C.
>
> I've walked through the tree and have replaced all the easy ones.
> The problem I'm having now is with '&'.
>
> I've tried this:
>
> '&[^amp;|lt;|gt;]'
>
> It works but if the document has  ' This & is called an ampersand.'
> the regex tells me to replace '& ' (including space).  How can
> I properly write the regex so that it only gives me a pointer to the
> '&' and not the '&' and next character?

Hmm.  A space is not one of the characters in the negated
character class.  It looks like that regexp will match an ampersand
followed by any single character that isn't an 'a', 'm', 'p', ';', etc.

It looks like you might have used square brackets instead of
parentheses, but I'm still not sure how that would work.  An English
version of the regular expression might help me to understand what
you're after.

-- 
  Ed Cashin <ecashin at noserose.net>


More information about the Ale mailing list