This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

regexp matching with a $string

Help for those learning Tcl or writing their own scripts.
Post Reply
s
stilllearning
Voice
Posts: 8
Joined: Sun Jan 29, 2006 1:58 am

regexp matching with a $string

Post by stilllearning »

I have a $string that contains a bunch of special characters that regexp will pick up as expressions... so how can I do...

if {[regexp $string $matchstring]} { ... }

since that won't work, what i am looking for is a way to negate expressions like \. for a period but for the entire $string to make it literal.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

This is a proc that will return <number of special chars> on special chars and 0 on alphabetic and nummeric chars..

Code: Select all

proc special {arg} {
  if {[regexp -nocase -all {[^a-z0-9]} $string -> n]} {
    return $n
  }
  return 0
}
XplaiN but think of me as stupid
Post Reply