Posix search for ] in brackets

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
wraith10
Posts: 2
Joined: Mon Apr 04, 2011 11:23 pm

Posix search for ] in brackets

Post 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?
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post 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]+
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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).
Post Reply