Reputation: 390
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.
Upvotes: 0
Views: 498
Reputation: 10666
It may be simpler:
if ( $line =~ /DESCR: "([^"]+)"/ ) {
print "$1\n";
}
Upvotes: 0
Reputation: 672
Take a look, this pattern can match double quoted in string:
if ($line =~ /DESCR: \"((?:[^\\"]|\\.)*)\"/) {
print "$1\n";
}
Upvotes: 0
Reputation: 187
$str = 'DESCR: "10GE SR"';
if ($str =~ /DESCR: \"([a-zA-Z0-9\s]+)\"/) {
print "$1\n";
}
Upvotes: 2