Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Capturing groups where the ending is optional

by tybalt89 (Vicar)
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 taking refuge in the Monastery: (5)
As of 2018-11-16 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (193 votes). Check out past polls.

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