Link to home
Start Free TrialLog in
Avatar of marchent
marchentFlag for Bangladesh

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?
Avatar of nedfine
nedfine
Flag of India image

/^(\"|\')i am a boy\1/
/(["'])i am a boy\1/
Avatar of marchent

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"
ASKER CERTIFIED SOLUTION
Avatar of nedfine
nedfine
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial