Timeline for Regex to replace multiple spaces with a single space
Current License: CC BY-SA 2.5
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 21, 2016 at 13:03 | comment | added | T4NK3R | I do. Used for full-text search (and snippet-display): No random tabs, non-breakers or thingymajigs, please. | |
Dec 30, 2009 at 18:11 | comment | added | watain | EvanCarroll you fail because \s\s+ is definitely different to \s+. \s\s+ would match '\t\t' or '\t\t\t' but NOT '\t'. And that's what it's all about, you don't want replace every f-en single whitespace character. | |
Dec 30, 2009 at 17:55 | comment | added | Evan Carroll | The first one is totally pointless, \s\s+ means, an \s followed by one or more \s+, which can be reduced to a single \s+, the second example is more accurate because we only want to replace double spaces, not newlines, the third is more optimized because it only applies to examples with 2+ spaces. But str.replace(/ +(?= )/g,'');, only applies to examples with 2+ spaces but saves overwriting a space with a space step. | |
Dec 30, 2009 at 17:45 | history | edited | meder omuraliev | CC BY-SA 2.5 |
added 298 characters in body
|
Dec 30, 2009 at 17:38 | history | edited | meder omuraliev | CC BY-SA 2.5 |
added 307 characters in body; added 145 characters in body
|
Dec 30, 2009 at 17:32 | history | answered | meder omuraliev | CC BY-SA 2.5 |