marchent
asked on
Easy Perl Regex
i need to match these with quote from a lagre string
'i am a boy'
or
"'i am a boy"
my current regex is /('|")i am a boy('|")/
but it returns matches like
'i am a boy" < ----- first single quote, last double quote
"i am a boy" < ----- first double quote, last single quote
i don't want to do like /'i am a boy'|")i am a boy"/
does anyone know?
'i am a boy'
or
"'i am a boy"
my current regex is /('|")i am a boy('|")/
but it returns matches like
'i am a boy" < ----- first single quote, last double quote
"i am a boy" < ----- first double quote, last single quote
i don't want to do like /'i am a boy'|")i am a boy"/
does anyone know?
/^(\"|\')i am a boy\1/
/(["'])i am a boy\1/
ASKER
i want this should work, not matching....
$str = "\'cat\"";
if($str =~ /(["'])cat\1/){
print "YES\n";
}
else{
print "NO\n";
}
it should match all below.
'cat"
"cat'
'cat'
"cat"
$str = "\'cat\"";
if($str =~ /(["'])cat\1/){
print "YES\n";
}
else{
print "NO\n";
}
it should match all below.
'cat"
"cat'
'cat'
"cat"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.