Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: greedy subexpression between two nongreedy ones

by Anonymous Monk
on Jun 03, 2015 at 01:38 UTC ( [id://1128891]=note: print w/replies, xml ) Need Help??


in reply to greedy subexpression between two nongreedy ones

Just trying to see how many '?' I can get in one regex :)

s/,.*?(?:(cd).*?)??,/=$1=/

This will, of course, give "Use of uninitialized value $1 in concatenation (.)" if you use warnings. Here's a fix for that, if needed.

s;,.*?(?:(cd).*?)??,;=@{[$1 // '']}=;

or

s/,.*?(?:(cd).*?)??,/$1 ? "=$1=" : "=="/e # without that @{[]} trick

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found