Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use "[" in regexp statements?

0 views
Skip to first unread message

mrby

unread,
Aug 25, 2004, 11:19:29 PM8/25/04
to
Hi,

I am swamped by matching two strings which contain "[" characters.
expect(0,string) stores a string containing "[". Then, I want to verify
it with a pattern, since tcl's "[" has special meaning, it can not work
as I wanted!

I tried to drop these "["s in expect(0,string), but I have not found a
method to do so.

What could I do?

--
Alan

Arjen Markus

unread,
Aug 26, 2004, 4:23:28 AM8/26/04
to

Well the "[" character has a special meaning for regular expressions
too,
but in both cases a well-placed "\" will remove the magic.

Try:

set string "\[ABC\]"
regexp {\[A} $string

(I almost always use braces when specifying regular expressions as this
limits the conflicts between regexp and Tcl to the minimum)

Regards,

Arjen

0 new messages