|
|
| Perl-Sensitive Sunglasses | |
| PerlMonks |
Non-greedy substitutionby Bod (Parson) |
| on Nov 15, 2024 at 19:06 UTC ( [id://11162727]=perlquestion: print w/replies, xml ) | Need Help?? |
|
Bod has asked for the wisdom of the Perl Monks concerning the following question: I thought I was OK with basic regular expressions, but the behaviour of this has bamboozled me... Can you please explain what I am doing wrong?
The result I want is for the list to have a comma separating each item except the last two items which will be separated by 'and'. So the results should be along these lines: However, the result of the one liner above is A and B, C I expected ,(.+?)$ to match a comma followed by the shortest possible text and the end of the string. I expected (.+?) to match ' C' as that is the shortest possible match and ? is used to make the match non-greedy
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||