问题
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