gmne
gmne

Reputation: 11

TCL, Regular Expression with ')', ']' or '}'

I'm trying, in TCL, to write a regex to detect 0 or more characters ')', ']' or '}' in the end of a string.

Like the following, using a, b and c instead of ), ] and }...

% regexp {[a]*$} "_______a" m
1
% put $m  ; # Prints affected portion
a
% regexp {[a]*$} "_______aaaa" m
1
% put $m
aaaa
% regexp {[ab]*$} "_______ababababab" m
1
% put $m
ababababab
% regexp {[abc]*$} "_______abcbabcaccc" m
1
% put $m
abcbabcaccc
%

I couldn't find how to escape the characters.

Thanks in advance.

Gmne


Added...

Precede Them with \ , for example, \) .

Thanks MRAB. Thats work good on Linux!. But it seems not to be the same for Windows..

% ### Windows:
% regexp {[\)\]\}]+$} "_____)))"
0
% regexp {[\)]+$} "_____)))" m
1
% puts $m
)))
% regexp {[\)]+$} "_____)\\\\" m
1
% puts $m
)\\


% ### Linux
% regexp {[\)\]\}]+$} "_____)))" m
1
% puts $m
)))

Any suggestions?

Upvotes: 1

Views: 468

Answers (1)

MRAB
MRAB

Reputation: 20644

Precede them with \, for example, \).

Upvotes: 5

Related Questions