Re: Variable inside regular expression
- From: davidfilmer@xxxxxxxxx
- Date: 30 Jun 2006 00:59:04 -0700
mattwoolnough@xxxxxxxxx wrote:
Is it possible to use variables inside regex?
That's a very simple question, but you posted some not-so-simple code
to illustrate it.
One basic debugging technique that you should adopt is to write a
small, simple program that tests your question AND NOTHING MORE. That
will quickly and easily reveal if the problem is what you think it is
(that variables don't match in a regexp) or something completely
unrelated to that quesion.
Consider this code:
#!/usr/bin/perl
use strict; use warnings;
my $foo = 'foo';
my $string = "foobar";
print "YES" if $string =~ /$foo/;
__END__
Run it and find out the answer to your question. You could have
written this program and answered your own question with less time and
effort than it took you to ask it here.
--
David Filmer (http://DavidFilmer.com)
.
- References:
- Variable inside regular expression
- From: mattwoolnough
- Variable inside regular expression
- Prev by Date: Variable inside regular expression
- Next by Date: Re: Detecting line terminators in a CSV file
- Previous by thread: Variable inside regular expression
- Next by thread: Re: Variable inside regular expression
- Index(es):