Page 1 of 1

Posix search for ] in brackets

Posted: Mon Apr 04, 2011 11:42 pm
by wraith10
Consider the following Posix RegExp and search text:

Regex: [a\]]+
Text: baa[aa]aab

I would expect the regex to match aa]aa, but for some reason it matches a] instead. I think it's because TextPad doesn't recognise \]. If this is the case, then it's a bug.

Does anyone know how to solve/workaround this problem?

Posted: Tue Apr 05, 2011 9:32 am
by ben_josephs
This is not a bug. Some regex recognisers treat a backslash in a character class as an escape character, some don't. TextPad's regex recogniser doesn't. Use
[]a]+

Posted: Tue Apr 05, 2011 11:50 am
by MudGuard
and it is documented
Help - Help Topics - Reference Information - Regular Expressions
then scroll down to Class expressions.

It says under Simple Characters:

To match a right square bracket (]), it must be the first character of the class expression, after any initial circumflex (see Negated Class Expressions).