python - Sublime Text 3 API plugin for regex replacing text -


i'm writing small plugin in sublime text 3 replace empty lines. used re module regex replace text. these 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 ctrl+f = '^\n'. why pattern ^\n not working in plugin?

because didn't use multiline flag in code. try this:

re.sub(re.compile('^\n', re.multiline), '', s) 

Comments

Popular posts from this blog

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -

php - Prepared Statement Inner Join Cannot Pass Parameter by Reference -

c# - Value cannot be null or empty.\r\nParameter name: name -