View Single Post
  #5 (permalink)  
Old 03-27-2012, 02:34 PM
Glenn Jackman
Guest
 
Posts: n/a
Default Re: Can I use a variable for a regexp or other pattern?

At 2012-03-26 05:50PM, "Nomen Nescio" wrote:
> Eugene <eugene.mindrov@gmail.com> wrote:
>
> > On 26.03.2012 19:40, Eugene wrote:
> > > On 26.03.2012 19:36, Fritz Wuehler wrote:
> > >> Can I use a variable for a regexp pattern or other pattern? For example
> > >>
> > >> regexp {[a-z]\.txt} $string filename
> > >>
> > >> I want to assign "[a-z]\.txt" to a variable and then do something like
> > >>
> > >> regexp {$regExpression} $string filename
> > >
> > > (bin) 51 % regexp $re $filename
> > > 1


Take note of how the command syntax appears in the man page:
http://tcl.tk/man/tcl8.5/TclCmd/regexp.htm

regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?

Note there's no quotes or braces around 'exp' -- it can be a string, a
variable reference, the result of a command, anything that is a single
word.

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
Reply With Quote