Greediness is not an issue for the OP because using a character class ([^"]*) constrains the match in any case.
Good point.
The double quote pairing is in fact correct
# /^set\szone\s("([^"]*)"|id\s\d+\s"([^"]*)")/ # ^ ^ ^ ^
Yes, it is actually the first format which has the right parenthesis in the wrong place. [Update 1: Apparently, I need better glasses! Sorry for the noise here.] But, as you say, that wasn’t the OP’s problem either.
So, try again (with thanks to Anonymous Monk, below):
if ($line =~ /^set\szone\s("[^"]*")|id\s\d+\s("[^"]*")/) { my $zone = $1 // $2; print "Config line=> $lineCount; Value=> $line; zone=> $zo +ne\n"; }
Hope that actually does help!
Update 2:Your simplification is at the cost of matching almost anything.
Well, that’s a bit of an overstatement. Here is the OP’s original requirement:
Basically I want to match the first value found between double quotes although there are two different formats for the lines.
My first solution does match “the first value found between double quotes.” But, as you point out, it doesn’t take account of the 2 specific formats. My second solution will match only on one or other of these formats.
Athanasius <°(((>< contra mundum
In reply to Re^3: Problem with alternating regex?
by Athanasius
in thread Problem with alternating regex?
by dwlepage
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |