Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Capturing groups where the ending is optional

by tybalt89 (Priest)
on Jan 15, 2018 at 00:03 UTC ( #1207247=note: print w/replies, xml ) Need Help??


in reply to Capturing groups where the ending is optional

#!/usr/bin/perl # http://perlmonks.org/?node_id=1207241 use strict; use warnings; my $specific = 'right'; while(<DATA>) { chomp; /(?|(.*?)($specific.*)|(.*)())/; printf "%-12s \\1=%4s \\2=%s\n", $_, $1, $2; } __DATA__ left right rightabc leftright leftrightabc

Outputs:

left \1=left \2= right \1= \2=right rightabc \1= \2=rightabc leftright \1=left \2=right leftrightabc \1=left \2=rightabc

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1207247]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2018-07-18 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (393 votes). Check out past polls.

    Notices?