in reply to Non-greedy substitution
«,» matches a comma, then «.+?» matches the least possible, then it matches the end of the string or a LF at the end of the string.
01234567 position A, B, C
Full:
Summary:
If «.+?» were to match any less, the «$» wouldn't match.
Solution:
sub join_list { return "none" if !@_; # ??? my $last = pop; return $last if !@_; return join( ", ", @_ ) . " and " . $last; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Non-greedy substitution
by Bod (Parson) on Nov 15, 2024 at 19:38 UTC | |
by ikegami (Patriarch) on Nov 15, 2024 at 20:00 UTC | |
by Bod (Parson) on Nov 15, 2024 at 21:38 UTC | |
by ikegami (Patriarch) on Nov 18, 2024 at 01:34 UTC | |
|
Re^2: Non-greedy substitution
by Bod (Parson) on Nov 15, 2024 at 19:27 UTC | |
by ikegami (Patriarch) on Nov 15, 2024 at 19:55 UTC | |
by Paladin (Vicar) on Nov 15, 2024 at 19:58 UTC | |
by ikegami (Patriarch) on Nov 15, 2024 at 20:14 UTC |