Delete lines with PythonScript
-
Hello,
I am using PythonScript and want to delete the whole line. Right now, I am using this:
editor.rereplace(r’^.: “”.$', ‘’)
and I am left with empty lines.
I can manually go to:
edit>line operations > remove empty lines.
but I do not see that option in the documentation PythonScript.I have tried.
editor.deleteLine(‘^.: “”.$’)
and this
editor.replaceWholeLine (r’^.: “”.$', ‘’)What setting or regex syntax do I need to include?
Any help would be grateful.
-
@Brian-Higdon said in Delete lines with PythonScript:
I am using PythonScript and want to delete the whole line
editor.deleteLine(line)
, whereline
is the line number you wish to delete.If you want to do it with
rereplace
, you need a correct pattern to match the line(s) to delete. I can’t tell from your posting what that is. But if you are “left with empty lines” then it probably means you didn’t include the line-ending in your pattern with\R
and indeed I don’t see that in your pattern.Maybe your “remove empty lines” comment is leading…about what you want to do… so let’s proceed with that:
You can execute that command in code with
notepad.menuCommand(MENUCOMMAND.EDIT_REMOVEEMPTYLINES)
With that as the basis of understanding, you could also do it with
editor.rereplace(r'^\R', '')
Oh, wait…I think the empty lines only comes into it after you’ve done your
rereplace
and it didn’t do what you wanted.I’m so confused… :-(
-
@Alan-Kilborn Thank you for getting back to me so quickly.
Yes, you are correct on my regex string. Adding \R did what I needed it to do.
editor.rereplace(r’^.: “”.$\R’, ‘’)
You are not confused; I confusingly wrote my question.
The issue is solved.
Thank you.