Sunday 17 December 2017

javascript - Replace all whitespace characters

itemprop="text">

I want to replace all occurrences of
white space characters (space, tab, newline) in JavaScript.
How to do so?



I
tried:



str.replace(/ /gi,
"X")


class="post-text" itemprop="text">
class="normal">Answer



You want
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"
rel="noreferrer">\s





Matches a single white space
character, including space, tab,
form
feed, line feed.




Equivalent
to




[
\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]


in
href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-white-space"
rel="noreferrer">Firefox and [ \f\n\r\t\v] in
rel="noreferrer">IE.



/>

str = str.replace(/\s/g,
"X");



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...