in reply to Regex: Matching quoted text

If you use /^(?:"([^"]+)"|(-))$/, the matching expression is not always in the same variable, but it is always in $1 || $2 :)

Update: As tye wrote in his reply, it's $2 || $1.

Replies are listed 'Best First'.
Re^2: Regex: Matching quoted text
by JavaFan (Canon) on Jun 03, 2010 at 21:31 UTC
    If you use /^(?:"([^"]+)"|(-))$/, the matching expression is not always in the same variable, but it is always in $1 || $2 :)
    Eh, no. Consider:
    "0" =~ /^(?:"([^"]+)"|(-))$/;
    Then $1 || $2 is actually undefined (because $1 is 0, hence false, and $2 is undefined). If the OP uses 5.10 or later, he could use $1 // $2, but then there's a better solution available as well (see my other post).