in reply to Regex match at the beginning or end of string
Then the length of the regexs won't be an issue.my $pattern1 = qr{abc:\(?.*?\)?\s}; my $pattern2 = qr{${variable}.{0,5}\s}; if ($str =~ /$pattern1(.*?)$pattern2/) { print "matched $1"; } if ($str =~ /$pattern2(.*?)$pattern1/) { print "matched $1"; }
|
|---|