-1

I am trying to write regular expression to capture from value field( string "male") for the two below lines using single regular expression

option selected="selected" value="***male***"

option value="***male***" selected="selected"

i have written some thing like,

option\s*?(?:value="(.+?)" selected="selected")|(?:selected="selected" value="(.+?)")

even though it is matching entire line from the file but "male" string is not captured. Please suggest.

Jens
  • 67,715
  • 15
  • 98
  • 113

1 Answers1

0
local $/; $_ = <DATA>; $match=$_;
my @values;
while($match=~m/value="([^\"]*)"/g)
{
     push(@values, $1);
}
print join "\n", @values;

__DATA__
option selected="selected" value="***male***"
option value="***male***" selected="selected"
ssr1012
  • 2,573
  • 1
  • 18
  • 30