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), wherelineis 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\Rand 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
rereplaceand 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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login