正则表达式或用单个空格替换多个空间的方法 [英] Regex or way to replace multiple space with single space
本文介绍了正则表达式或用单个空格替换多个空间的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请您告诉我有没有办法用java或spring中的单个空格替换多个空格?任何stringUtils函数是否相同?
Could you please let me know is there any way to replace multiple space with single space in java or spring? Any stringUtils function for same?
喜欢
1.
test test
test test
2。
test test
test test
3。
test test
test test
推荐答案
替换多个空格
output = input.replaceAll("[ ]+", " ");
或者替换多个空格字符(包括空格,制表符,新行等)
Or replace multiple whitespace characters (including space, tab, new line, etc.)
output = input.replaceAll("\\s+", " ");
这篇关于正则表达式或用单个空格替换多个空间的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文