Home >Web Front-end >JS Tutorial >Get the data sent from the server and use JS to remove spaces using regular expressions_javascript skills
Until now this morning, I have been working on a very stupid question, and I have never found it.
If $str="";
$str = "$str-$sno";
This way , there will be a space in front of $str. After js obtains this value, the space must be removed
to remove the space function rstr=rstr.replace(/(^s*)|(s*$)/g,"" );
Another:
replace the left space(/(^s*)/g, "");
replace(/(s*$) the right space )/g, "");
In addition, if you check the program flow step by step and stop at the if, you must output the two values in the if at the same time for comparison, or add in front Go to # to see if there are spaces
To summarize
1. Wherever strings are used to connect, spaces may be generated. When split, there will be spaces that are different from the original ones. situation, therefore, be sure to remove the leading and trailing spaces
2. Especially when obtaining data from the server, JS must pay attention to the possibility of spaces.