regex - Why these commands fail if I concatenate them (with "|")? -


to turn this:

·     阿富汗 country1  ·     阿爾及利亞 country2  ·     孟加拉 country3   *  ·  不丹 country4 (請參閱下列*說明處) 

into this:

country1,country2,country3,country4 

i following:

%s/[^\x00-\x7f]//g 

remove chinese characters.

%s/\s\+$//g 

remove trailing white spaces

%s/\s\+//g 

remove remaining whites paces

g/^$/d 

remove empty lines

%s/\n/,/g 

connected each line single 1 (each word separated comma).

now want in 1 command. concatenated commands:

%s/[^\x00-\x7f]//g|%s/\s\+$//g|%s/\s\+//g|g/^$/d|%s/\n/,/g  

which produces this:

country1,country2,,country3,,country4, 

i find strange since commands work if use them separately.

what happening here?

not ex command can concatenated. commands, :global command, can take sequence of commands, , therefore eat remaining arguments, including | command separator. see :help :bar list of such commands. provides solution if want include such command in sequence: need enclose command :execute. applied problem, becomes:

%s/[^\x00-\x7f]//g|%s/\s\+$//g|%s/\s\+//g|exe 'g/^$/d'|%s/\n/,/g 

with this, last :s command applied entire buffer, , not within scope of :global command.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -