Home  >  Article  >  Backend Development  >  javascript - 请问匹配最后一个空格后的内容的正则表达式怎么写?

javascript - 请问匹配最后一个空格后的内容的正则表达式怎么写?

WBOY
WBOYOriginal
2016-06-06 20:27:502017browse

<code>请问匹配最后一个空格后的内容的正则怎么写?

或者说匹配最后一个空格前的内容的也可以。

我自己试了几种都没有用。

还有\s 的话,到底能不能匹配到中文的空格呢?
</code>

回复内容:

<code>请问匹配最后一个空格后的内容的正则怎么写?

或者说匹配最后一个空格前的内容的也可以。

我自己试了几种都没有用。

还有\s 的话,到底能不能匹配到中文的空格呢?
</code>

js:

<code>/\s+(\S*)$/</code>

关键:

\S 非空 $行尾

你的意思应该是半/全角空格吧?\s是可以匹配的。楼上的正则就是匹配空格后的内容的正则

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