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

Help for those learning Tcl or writing their own scripts.
Post Reply
S
StaleJoke
Voice
Posts: 10
Joined: Tue Nov 29, 2005 8:04 pm

regexp

Post by StaleJoke »

Code: Select all

set r [regexp -nocase -all {$t1|$t2} $arg]
Doesn't work. Any corrections need to be done ?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

$ has special meaning inside {} in regexp. Try "" instead {}.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

Variables are not expanded inside of curly braces, you need to use double quotes as Sir_Fz suggested when using variables for matchin with regexp.
User avatar
avilon
Halfop
Posts: 64
Joined: Tue Jul 13, 2004 6:58 am
Location: Germany

Post by avilon »

Code: Select all

set RE {$t1|$t2}

set r [regexp -nocase -all -- [subst -nocommands -nobackslashes $RE] $arg]
S
StaleJoke
Voice
Posts: 10
Joined: Tue Nov 29, 2005 8:04 pm

Post by StaleJoke »

Done.

Code: Select all

set r [regexp -nocase -all -- [subst -nocommands -nobackslashes $RE] $arg]
But problem happens when it the var $RE is ) or a (
The error it spews out is

Tcl error [rep_fld]: couldn't compile regular expression pattern: parentheses () not balanced

Any suggestions ?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set RE [string map {( \\( ) \\)} $RE]
S
StaleJoke
Voice
Posts: 10
Joined: Tue Nov 29, 2005 8:04 pm

Post by StaleJoke »

On the same lines, if the bot encounters an astrix * as part of the word ( e.g. word* ) it gives me the error as:

Tcl error [repact_fld]: couldn't compile regular expression pattern: quantifier operand invalid
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set RE [string map {( \\( ) \\) * \\*} $RE]
You might want to add more special characters to this list.
Post Reply