I'm writing a small plugin in Sublime Text 3 to replace all empty lines. I used re module to do regex replace text. These are my codes test on console:
>>> text = 'abc \n\nOk'
>>> print(text)
abc
Ok
>>> text = re.sub(r'^\n','',text)
>>> text
'abc \n\nOk'
I can search on ST3 by Ctrl+F = '^\n'. Why does the pattern ^\n not working in the plugin?
Because you didn't use multiline flag in your code. Try this:
re.sub(re.compile('^\n', re.MULTILINE), '', s)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With