You probably don't want a character class [#\d+,], but rather a (non-capturing) group: (?:#\d+,). But the real problem you're having is that the preceding .* is gobbling up the optional part. So, make it non-greedy, i.e. .*?
for my $update_p4filelog ( "...xyz branch from //source/qcom/qct/multimedia/qtv/player/audiop +layer/rel/1.1/src/file.cpp#1,#8", "...xyz branch from //source/qcom/qct/multimedia/qtv/player/audiop +layer/rel/1.1/src/file.cpp#8", ) { my ($path, $ver) = $update_p4filelog =~ /branch from (.*\/.*?)(?:# +\d+,)?(#\d+)$/; my $update_base_branched_p4path = "$path$ver"; print "$update_base_branched_p4path\n"; } __END__ //source/qcom/qct/multimedia/qtv/player/audioplayer/rel/1.1/src/file.c +pp#8 //source/qcom/qct/multimedia/qtv/player/audioplayer/rel/1.1/src/file.c +pp#8
In reply to Re^9: Regex to grab data after the work "branch from"
by Anonyrnous Monk
in thread Regex to grab data after the work "branch from"
by perl_mystery
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |