in reply to greedy subexpression between two nongreedy ones
#!/usr/bin/perl # http://perlmonks.org/?node_id=1128703 use Data::Dump qw(pp); use strict; use warnings; pp [ map # explanation of regex s/ , # find a comma .*? # match as little as possible until you find (?: # grouping for either (cd) # cd :) .*? # which must be followed by as little as possible up to the + next , # comma | # or , # a comma ) # end either grouping / # replace with $1 # test for true to avoid "uninitialized" warning ? "=$1=" # =cd= : "==" # no cd because comma was found first /exr # eval, expanded, and return result of replacement(just for t +est) # rest of running code , ',abcefg,abcdefg,', ',abcdefg,abcdefg,' ]; __END__
|
---|