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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.