Regex match space not \n

六月ゝ 毕业季﹏ 提交于 2020-01-25 11:18:12

问题


Original text is

81277184956 0 31    10000    0    0  0  0  4
afdsf sadfdsf

I want to replace all space with character "|" by regex at Sublime text 2.

Expected result should be

81277184956|0|31|10000|0|0|0|0|4
afdsf|sadfdsf

If i use pattern "\s+", it will match \n too so that two lines change to one line. How to get correct result?


回答1:


Use [[:blank:]]+, which equals to [\x20\t]+

Click here for more details of Oniguruma Regular Expression syntax, regex module used in Sublime Text.




回答2:


You can add an exclusion "^".

\s+[^\n]



回答3:


regex=re.compile(' ') a=regex.sub('|',a)

This is how you can easily get the thing done.



来源:https://stackoverflow.com/questions/14190038/regex-match-space-not-n

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!