Regex newbie

G

gazza67

Anybody,

I want to use a regex in which the string for which we are searching
is a variable. Is this possible - it doesnt seem to work for me.

$a = "be";

$b="to be or not to be";
if ($b =~ m/$a/i )
print "this should be true";

$b = "apples and oranges";
if ($b =~ m/$a/i )
print "this should be false";



Cheers
Gary
 
K

kath

Anybody,

I want to use a regex in which the string for which we are searching
is a variable. Is this possible - it doesnt seem to work for me.

$a = "be";

$b="to be or not to be";
if ($b =~ m/$a/i )
print "this should be true";

$b = "apples and oranges";
if ($b =~ m/$a/i )
print "this should be false";

Cheers
Gary

Either you have to use post condition or have to close block after if
statement with brackets

print "this should be true" if ($b =~ /$a/i);

or

if ($b =~ /$a/i){
print "this should be true";
}

sudhir.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top