View Single Post
  #9 (permalink)  
Old 03-28-2012, 04:12 AM
Fritz Wuehler
Guest
 
Posts: n/a
Default Re: Can I use a variable for a regexp or other pattern?

Eugene <eugene.mindrov@gmail.com> 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
> >
> > but I can't get it to work. I also had no joy with string match and format
> > etc. Is there a way to do this? It seems like it would be good practice to
> > assign patterns to variables instead of hardcoding them. Thank you for the
> > help.
> >

> Here's the output from my TkCon:
>
> (bin) 49 % set filename blablah.txt
> blablah.txt
> (bin) 50 % set re {[a-z]\.txt}
> [a-z]\.txt
> (bin) 51 % regexp $re $filename
> 1
> (bin) 52 %
>
> To make things work in your case just remove brackets from around your
> $regExpression variable in regex command


DOH!!!

Thanks! I thought I knew what the problem was but I didn't. I was setting
the variable to contain the regexp incluing the { }

Reply With Quote