0
DESCR: "10GE SR" 

i need match this above part which is part of my rest of the string. Im using regex in perl. i tried

if ($line =~ /DESCR: \"([a-zA-Z0-9)\"/) { 
   print "$1\n";
}

but im not able to understand how to consider spaces inside my string. these spaces can occur any where within the quotes. can someone help me out.

3 Answers 3

2
$str = 'DESCR: "10GE SR"';

if ($str =~ /DESCR: \"([a-zA-Z0-9\s]+)\"/) { 
    print "$1\n";
}
Sign up to request clarification or add additional context in comments.

Comments

0

Take a look, this pattern can match double quoted in string:

if ($line =~ /DESCR: \"((?:[^\\"]|\\.)*)\"/) { 
   print "$1\n";
}

Comments

0

It may be simpler:

if ( $line =~ /DESCR: "([^"]+)"/ ) { 
   print "$1\n";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.