#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11159717 use warnings; $_ = "a b=c"; /(a)(.*?)(?|b=(\w)|()\z)/ or die;; printf "\$2 is [%s]\n", defined $2 ? $2 : "undefined"; printf "\$3 is [%s]\n", defined $3 ? $3 : "undefined"; $_ = "a c=c"; /(a)(.*?)(?|b=(\w)|()\z)/ or die;; printf "\$2 is [%s]\n", defined $2 ? $2 : "undefined"; printf "\$3 is [%s]\n", defined $3 ? $3 : "undefined";
Outputs:
$2 is [ ] $3 is [c] $2 is [ c=c] $3 is []
In reply to Re: RE greediness
by tybalt89
in thread RE greediness
by Danny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |