From: Keith on 23 Apr 2010 11:24 % set x 567 567 % string length $x 3 % regexp "\d{[string length $x]}" $x d 0 I have tried using set e [string length $x] eval regexp "\d{$e}" $x d also with no matching. TIA. -- Best Regards, Keith http://home.comcast.net/~kilowattradio/ I'm Your Huckle Berry http://www.youtube.com/watch?v=KfbAFgD2mLo
From: Donald G Porter on 23 Apr 2010 11:44 Keith wrote: > % set x 567 > 567 > % string length $x > 3 > % regexp "\d{[string length $x]}" $x d > 0 You forgot that Tcl syntax defines backslash substitution. Here's one way to makes things work: % regexp [subst -nobackslashes {\d{[string length $x]}}] $x d 1
From: Glenn Jackman on 23 Apr 2010 12:12 At 2010-04-23 11:24AM, "Keith" wrote: > % set x 567 > 567 > % string length $x > 3 % set re "\d{[string length $x]}" d{3} Notice the leading backslash has disappeared -- Tcl's double quoted strings substitute backslash sequences (eg. "\n") You might want to do this instead % regexp "\\d{[string length $x]}" $x d 1 % set d 567 -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous
From: Aric Bills on 23 Apr 2010 12:17 On Apr 23, 9:24 am, Keith <kilowattra...(a)use-reply-to.invalid> wrote: > % set x 567 > 567 > % string length $x > 3 > % regexp "\d{[string length $x]}" $x d > 0 > > I have tried using > > set e [string length $x] > eval regexp "\d{$e}" $x d > > also with no matching. > > TIA. > -- > Best Regards, Keithhttp://home.comcast.net/~kilowattradio/ > I'm Your Huckle Berryhttp://www.youtube.com/watch?v=KfbAFgD2mLo Depending on what you're trying to accomplish, there's also [string is integer -strict $x]...
From: Uwe Klein on 23 Apr 2010 12:41 Keith wrote: > % set x 567 > 567 > % string length $x > 3 > % regexp "\d{[string length $x]}" $x d > 0 % regexp \\d\{[string length $x]\} $x d 1 wouldn't regexp {^\d*$} $x d suffice? % regexp {^\d*$} $x d 1 % set x abc567 abc567 % regexp {^\d*$} $x d 0 % uwe
|
Pages: 1 Prev: TclOO: Renaming "new" and "create" methods? Next: fickle problem... |