The following small series will provide you with a regular expression (recommended) for removing spaces and line breaks in JavaScript ). I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at the small Editor. When programming a few days ago, I encountered a problem that I had to solve for a long time. It really drove me crazy! Put a string in setTimeout and there is no way to execute it. Later it was found that there was a line break behind the string. If you don't take a closer look, you can use a regular expression to remove the line break.
// Remove the space String. prototype. trim = function () {return this. replace (/\ s +/g, "") ;}// remove the wrap function ClearBr (key) {key = key. replace (/<\/?. +?> /G, ""); key = key. replace (/[\ r \ n]/g, ""); return key;} // remove the left space function LTrim (str) {return str. replace (/^ \ s */g, "") ;}// remove right space function RTrim (str) {return str. replace (/\ s * $/g, "") ;}// remove the space at both ends of the string function trim (str) {return str. replace (/(^ \ s *) | (\ s * $)/g, "");} // remove the space in the string. function CTim (str) {return str. replace (/\ s/g, '');} // whether the string is_digitals (str) is composed of digits) {var reg =/^ [0-9] * $/; // match the return reg. test (str );}
Now I find myself more and more fond of using regular expressions! It is simple and intuitive. Of course, you are familiar with regular expressions. I also tried to write this JS method to delete the line feed myself, which really made me implement it!
The above JS Regular Expressions (recommended) for removing spaces and line breaks are all the content shared by the editor. I hope to give you a reference and support for PHP.
For more articles on JS Regular Expressions (recommended) for removing spaces and line breaks, please follow the PHP Chinese website!