Page 1 of 1

Something wrong with regex?

Posted: Mon Nov 01, 2010 12:48 pm
by nickholmes
Hi

Am I doing something wrong? I can't get Find>Regular expressions to match what I want using the 'Character Class Operators'.

if I create a new document, and enter

Code: Select all

01234 abcdefg
on the first line, then use the find tool to search for

Code: Select all

[0-9]
it matches what I would expect; 0, 1, 2, 3 and 4, but if I search for

Code: Select all

[:digit:]
it matches d and g in abcdefg.

Likewise, if I put a space in the 'Find what' box, it correctly matches the space in the text, but if I search for

Code: Select all

[:space:]
it matches a, c and e in abcdefg.

I have checked that 'Find>Regular expression' is ticked and 'Preferences>Editor>Use POSIX regex syntax' is not ticked.

Do I have to escape the Character Class Operators? I've tried

Code: Select all

\[:space:]
but it doesn't match anything.

Thanks

Nick

Posted: Mon Nov 01, 2010 1:34 pm
by ben_josephs
In TextPad's help under How to... | Find and Replace Text | Use Regular Expressions:
Character Class Operators "[: ... :]":

These can be used in class expressions as an alternative way of representing classes of characters. For example, [a-z0-9] is equivalent to [[:lower:][:digit:]]. (Note the extra pairs of brackets.)
And under Reference Information | Regular Expressions:
Character Class Operators:

These can be used as an alternative way of representing classes of characters. For example, [a-z] is equivalent to [[:lower:]] and [a-z0-9] is equivalent to [[:lower:][:digit:]]. (Note the extra pairs of brackets.)