regex - How to write reg expression which uses some special characters? -


i write reg expression should not use special symbols other (/, \, -, [, ], <, >, $, ~, !, @, #, :, %). try:

  if { [regexp {^[\w/-\[\]<>$#~!@#%:\\\/]+$} $name] != 1 } {         puts "handle error";   } 

but not work.

for example such name io1?? it's not treated error

could help?

you have escape - in character class or put @ beginning - otherwise it's interpreted range:

regexp {^[\w/\-\[\]<>$#~!@#%:\\\/]+$} $name 

or

regexp {^[-\w/\[\]<>$#~!@#%:\\\/]+$} $name 

the range between / , \[ seems contain ?.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -