Sort ignoring leading 'the'
-
Is it possible to sort lines ignoring leading words like ‘the’ and ‘a’?
-
There is no builtin way of doing that. If you know the list of articles you want to skip, you could make a multistep process to do it:
- Move
The
,An
,A
to the end of each line, after a special marker
FIND =(?i-s)^(\h*(?:The|An|A)\h)(.*)$
REPLACE =$2►$1
SEARCH MODE = Regular Expression
Replace All - Sort
- Move the end back to thh beginning:
FIND =(?i-s)^(.*)►(.*)$
REPLACE =$2$1
SEARCH MODE = Regular Expression
Replace All
BEFORE:
Another Time The Wheel of Time A Wrinkle in Time An Acceptible Time These are the Times
AFTER:
An Acceptible Time Another Time These are the Times The Wheel of Time A Wrinkle in Time
You can add more to the list
(?:The|An|A|Yet|Another|Here|...)
- Move
-
@PeterJones said in Sort ignoring leading 'the':
There is no builtin way of doing that. If you know the list of articles you want to skip, you could make a multistep process to do it:
- Move
The
,An
,A
to the end of each line, after a special marker
FIND =(?i-s)^(\h*(?:The|An|A)\h)(.*)$
REPLACE =$2►$1
SEARCH MODE = Regular Expression
Replace All - Sort
- Move the end back to thh beginning:
FIND =(?i-s)^(.*)►(.*)$
REPLACE =$2$1
SEARCH MODE = Regular Expression
Replace All
BEFORE:
Another Time The Wheel of Time A Wrinkle in Time An Acceptible Time These are the Times
AFTER:
An Acceptible Time Another Time These are the Times The Wheel of Time A Wrinkle in Time
You can add more to the list
(?:The|An|A|Yet|Another|Here|...)
Oh wow, thanks - perfect!!! I realise it’s not possible to create a macro for this but could it be done in a python script? Then I could create a button for it.
- Move
-
@deleelee said in Sort ignoring leading 'the':
I realise it’s not possible to create a macro for this but could it be done in a python script?
You can record that as a macro. There’s a whole section in the Online User Manual about the details of search/replace macros
And virtually anything you can do in Notepad++ can be run from PythonScript (though things like settings and interacting with some dialogs requires some behind the scenes hacking)
-
This post is deleted! -
@PeterJones said in Sort ignoring leading 'the':
You can record that as a macro
Ooops sorry. I was basing that on a comment you made on a previous post of mine but I misunderstood part of it and thought you had said only search/replace could be recorded as macro. You had actually said the only ‘dialog-based action’ that could be recorded was a search/replace. I thought the sort in this instance would be problematic but it’s not a dialog. So I’ve created a macro and can now sort with ignore. Thanks again!!