in reply to capture value from two patterns
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: capture value from two patterns
by AnomalousMonk (Archbishop) on Aug 20, 2020 at 23:08 UTC | |
Re^2: capture value from two patterns
by vitoco (Hermit) on Aug 20, 2020 at 20:36 UTC |