Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-09-19 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (165 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!