加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 02:28:47 所属栏目:百科 来源:网络整理
导读: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

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".

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读