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
> >>
> >> 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 
>
> Completely forgot to explain the behavior - brackets just prevent your
> regExpression variable from evaluation/expanding...
I knew that but I didn't know what to do about it!
Thanks again mate :-)