Home  >  Article  >  Web Front-end  >  How to remove whitespace characters from string

How to remove whitespace characters from string

坏嘻嘻
坏嘻嘻Original
2018-09-14 16:32:302692browse

This article mainly introduces how to delete blank characters in strings. I hope you can learn patiently.

replace regular matching method is as follows:

Remove all spaces in the string: str = str.replace(/\s*/g,"" );

Remove spaces at both ends of the string: str = str.replace(/^\s*|\s*$/g,"");

Remove the spaces on the left side of the string: str = str.replace(/^\s*/,"");

Remove the spaces on the right side of the string Spaces on the side: str = str.replace(/(\s*$)/g,"");

Note:

1."/ /" This is a fixed writing method,
2. "\s" is a transfer symbol used to match any whitespace character, including spaces, tabs, form feeds, etc.,
3. "g" means that global matching will replace All matching substrings, if "g" is not added, will end after matching the first one
.

How to remove whitespace characters from string

Related recommendations:

JS implementation loads js and css files when needed_html/css_WEB-ITnose

An example of interaction between php and js

The above is the detailed content of How to remove whitespace characters from string. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn