| View previous topic :: View next topic |
| Author |
Message |
StaleJoke Voice
Joined: 29 Nov 2005 Posts: 10
|
Posted: Wed May 03, 2006 7:52 pm Post subject: regexp |
|
|
| Code: |
set r [regexp -nocase -all {$t1|$t2} $arg]
|
Doesn't work. Any corrections need to be done ? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed May 03, 2006 8:42 pm Post subject: |
|
|
$ has special meaning inside {} in regexp. Try "" instead {}. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
DragnLord Owner

Joined: 24 Jan 2004 Posts: 711 Location: C'ville, Virginia, USA
|
Posted: Wed May 03, 2006 9:01 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
avilon Halfop

Joined: 13 Jul 2004 Posts: 64 Location: Germany
|
Posted: Thu May 04, 2006 11:54 am Post subject: |
|
|
| Code: | set RE {$t1|$t2}
set r [regexp -nocase -all -- [subst -nocommands -nobackslashes $RE] $arg] |
|
|
| Back to top |
|
 |
StaleJoke Voice
Joined: 29 Nov 2005 Posts: 10
|
Posted: Thu May 04, 2006 8:02 pm Post subject: |
|
|
Done.
| Code: |
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 ? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
|
| Back to top |
|
 |
StaleJoke Voice
Joined: 29 Nov 2005 Posts: 10
|
Posted: Wed May 10, 2006 8:54 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed May 10, 2006 8:57 pm Post subject: |
|
|
| Code: | | set RE [string map {( \\( ) \\) * \\*} $RE] |
You might want to add more special characters to this list. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
|