Logo

Programming-Idioms

History of Idiom 219 > diff from v15 to v16

Edit summary for version 16 by programming-idioms.org:
[Perl] Fix target t. Fix regexp to replace all matches.

Version 15

2020-05-03, 19:29:02

Version 16

2020-05-03, 19:34:27

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Idiom #219 Replace multiple spaces with single space

Create string t from the value of string s with each sequence of spaces replaced by a single space.

Explain if only the space characters will be replaced, or the other whitespaces as well: tabs, newlines.

Extra Keywords
collapse repeated
Extra Keywords
collapse repeated
Code
my $t = $s;
$s =~ s/ +/ /;
Code
my $t = $s;
$t =~ s/ +/ /g;
Comments bubble
Replace only space
Comments bubble
Replace only space
Doc URL
https://perldoc.perl.org/perlre.html
Doc URL
https://perldoc.perl.org/perlre.html