Character Class not recognized in Regular expression

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
forest78
Posts: 1
Joined: Wed Feb 18, 2004 11:03 am

Character Class not recognized in Regular expression

Post by forest78 »

Hi,

My intention is to insert newlines before each instance of uppercase characters. I already tried the following:

replace \([:upper:]\) with \n\1

The checkbox "Regular Expression" is enabled. However, instead of treating [:upper:] as a character class, Textpad replaces all instances of u, p, e and r.

Is this expected behaviour?

Thanks,

- R a l p h -
michaeldinning
Posts: 3
Joined: Tue Jan 20, 2004 11:31 am

Post by michaeldinning »

2 sets of [] around the :upper: is what is needed.

ie: replace \([[:upper:]]\) with \n\1

'Match Case' must be checked, otherwise :upper: matches all lower case charactors also[/b]
Jens Hollmann
Posts: 26
Joined: Tue Mar 04, 2003 7:33 am

Post by Jens Hollmann »

Yes. For some unknown reason these character classes are only valid inside a group of characters which must be enclosed in square brackets.

The correct expression to look for a single upper case character therefore is:

[[:upper:]]

HTH

Jens
User avatar
s_reynisson
Posts: 939
Joined: Tue May 06, 2003 1:59 pm

Post by s_reynisson »

This is called a POSIX bracket-expression and it can describe a special range like class.
Special because it uses the current locale.
So [a-z] finds just that, a to z, but [[:lower:]] finds a to z and letters like áýúóþæðö,
or whatever lowercase characters that are defined in your locale.
[:lower:] is the POSIX range character class and the extra [] stand for the
POSIX bracket-expression. From Mastering RegEx's, 2nd Ed.
Hope I mangled this correctly together! ;)
Then I open up and see
the person fumbling here is me
a different way to be
Post Reply