python - What should I do if I want to remove the extra blank lines in the following code? How can I use regular expressions to achieve this?
PHP中文网
PHP中文网 2017-05-18 10:53:03
0
2
680

/

52.html
152254.html
152255.html
152256.html
152257.html

8172396.html
8177822.html
8180348.html

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
仅有的幸福

function delAmpty(str) {

 return str.replace(/\s/g,'');

}

alert(delAmpty('hello world'));

This roughly means s matches the whitespace character, and replace is ok. Try it yourself

Be sure to add /g when replacing everything!

迷茫

My guess is to replace two newlines with one newline, also taking into account whether the blank lines contain spaces.

The above string is equivalent to:

a = '\\n\n52.html\n152254.html\n152255.html\n152256.html\n152257.html\n\n8172396.html\n8177822.html\n8180348.html';

I don’t know python, it’s implemented in JavaScript:

str.replace(/\n\s*\n/g,'\n');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template