Logo

Programming-Idioms

History of Idiom 219 > diff from v16 to v17

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

Version 16

2020-05-03, 19:34:27

Version 17

2020-05-03, 19:34:53

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/\s+/ /;
Code
my $t = $s;
$t =~ s/\s+/ /g;
Comments bubble
Replace all whitespace
Comments bubble
Replace all whitespace