正则表达式将字符串中的所有连续空格替换成一个空格

前端之家收集整理的这篇文章主要介绍了正则表达式将字符串中的所有连续空格替换成一个空格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Replace two or more spaces with a single space.

JAVA :
String oldStr = "AAA BBB";
String newStr =oldStr.replaceAll(" {2,}"," ");

JS :
var oldStr = "AAA BBB";
var newStr =oldStr.replace(//s{2,}/g," ");

sql :
If there two records in table A,the s of A2 is "aa bb" and "aaa bbb".
We can use the like :
UPDATE A SET A2=REGEXP_REPLACE(A2,'( ){2,}',' '),and then the new s of A2 is "aa bb" and "aaa bbb".

原文链接:/regex/363255.html

猜你在找的正则表达式相关文章