For those of you who tried to put together a “flatten” function cross browser to eliminate consecutive spaces and/or trim some text that is retrieved from the HTML page itself, you might have noticed that a simple regex of the kind
is simply not enough and occasionally Internet Explorer would still return a string with multiple consecutive space characters! The reason for that is that Internet Explorer does NOT treat
(non-breaking spaces) as a space — and therefore the
\s won’t match it! In order to include this in your match, look at W3C list of HTML entities, and it transpires that
and you’ll notice that now you “catch” the non-breaking spaces in IE as well as Firefox (which does the right thing and treats the non-breaking spaces as proper spaces) — yahoo!
More from my site