user1765418
user1765418

Reputation: 41

Regex match space not \n

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?

Upvotes: 1

Views: 2986

Answers (3)

raees888
raees888

Reputation: 1

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

This is how you can easily get the thing done.

Upvotes: 0

Flily Hsu
Flily Hsu

Reputation: 111

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

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

Upvotes: 1

jlujan
jlujan

Reputation: 1188

You can add an exclusion "^".

\s+[^\n]

Upvotes: 2

Related Questions