You may use the "branch reset" pattern:
#!/usr/bin/perl use strict; use warnings; use feature 'say'; for (qw(/key/123 /123-456)) { my ($id) = m!(?|/key/(\d+)|/(\d+)-\d+)!; say $id; } __DATA__ 123 123
EDIT: Added the missing leading slash in the second branch.
Greetings,
-jo
In reply to Re: capture value from two patterns
by jo37
in thread capture value from two patterns
by vitoco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |