Extending classes in regexps
I'm trying to find out how to `extend matching range' of those predefined
character-matching classes. For example, to use "\w" and add to it a full
stop mark; e.g. to match the string "hello_world.txt" using \w (to make the
regexp AS SHORT AS POSSIBLE), I'd imagine something like this should work:
but it doesn't. When used "[[:alnum:]_\.]*", though, it works. What I'm
trying to achieve are the shortest possible regexps and using predefined
classes is obviously the best way to do so. Any idea how to use classes this
gedas ČR s.r.o.
TGM 840, Mladá Boleslav
Phone: +420-(326)-711 408
Fax: +420-(326)-711 420
Cellphone: +420-(736)-738 619
- Hi David
> I'd imagine something like this should work: [\w\.]* but itBut it might not work as you like to ;-) The reason is that \ within
> doesn't. When used "[[:alnum:]_\.]*", though, it works.
 is _not_ a special character. So [\w\.] finds \ and w and \ again
and a point `.´ (because a point isn't a special char as well). The
same is true for [[:alnum:]_\.]. This also matches hello\word.txt.
So you have to use [[:alnum:]_.]\+ or \(\w\|\.\)\+. You can also use
the option \v ("very magic") and then write \v(\w|\.)+.
Note that [:alnum:] finds also special chars as ç, é, ö etc.,
whereas \w does not.
Not also that you have to use \+ instead of * because a* matches
zero or more `a´, but you probably want to match one or more `a´.