in reply to Extract pattern match from file
I just tweaked your regex a bit and used test data from haukex. I like his regexp-common solution, but for something simple, you are close.
Update: I saw the post from AnomalousMonk, re: "". That is why I changed the + to a * to handle that situation. And yes, if a quote went between 2 lines, the new line would get captured and have to be dealt with in some way.use warnings; use strict; my $data = do { local $/; <DATA> }; my @strings = $data =~ /\"([^\"]*)\"/g; print map{"<$_>\n"}@strings; =Prints <hello> <bar> <hello> <world> <bar> <baz> <> <> <example 1 for instance> =cut __DATA__ nothing "hello" foo "bar" quz "hello" "world" foo "bar" quz "baz" blah "" blah "" blah nothing "example 1 for instance"
|
|---|