Take the 2-minute tour ×

I have a problem. I have 1 variable

set a "mau_gigabitethernet0/0/cpu0/2"

with the help of regexp I need to fetch the 0/0/CPU0

I'm getting an error, “invalid escape \ sequence” can anyone help me..???

share|improve this question

1 Answer 1

up vote 4 down vote accepted

I'd look for something like this:

regexp {(?i)\d+/\d+/cpu\d+} $a extracted
puts $extracted

Note that the regular expression is in braces, not double-quotes. That is important. (If it was in double quotes, it would have to be "(?i)\\d+/\\d+/cpu\\d+" which is awkward.) Also, I use (?i) to mark it as a case-insensitive regular expression.

share|improve this answer
is there any advantage to use regexp {(?i)pattern} versus regexp -nocase {pattern}? –  glenn jackman May 16 '12 at 12:20
@glenn No advantage; I just prefer to write it like that because the lack of case-sensitivity is to me a part of the pattern. –  Donal Fellows May 16 '12 at 14:26
@DonalFellows Thank you so much...its working..now i am getting what mistake i made..i was using backslash with special characters..like for '/' i was using '\/'.. –  Pratibha Tomar May 17 '12 at 4:13
@PratibhaTomar Inside one of Tcl's regular expressions, a \/ is the same as a /. It's also harmless. But if you're putting the overall RE in "quotes", you've got a chance to have a fight between the Tcl language itself and the RE engine over backslashes; that's virtually always something you don't want! Put REs in {braces} if you can. (The times you can't are when you're building the RE from pieces in variables or returned by commands, but that's rather rare.) –  Donal Fellows May 17 '12 at 7:08

Your Answer


