Community
    • Login

    Sort ignoring leading 'the'

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 973 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • deleeleeD Offline
      deleelee
      last edited by

      Is it possible to sort lines ignoring leading words like ‘the’ and ‘a’?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @deleelee
        last edited by PeterJones

        @deleelee ,

        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:

        1. 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
        2. Sort
        3. 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|...)

        deleeleeD 1 Reply Last reply Reply Quote 2
        • deleeleeD Offline
          deleelee @PeterJones
          last edited by

          @PeterJones said in Sort ignoring leading 'the':

          @deleelee ,

          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:

          1. 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
          2. Sort
          3. 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.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP Offline
            PeterJones @deleelee
            last edited by PeterJones

            @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)

            deleeleeD 2 Replies Last reply Reply Quote 0
            • deleeleeD Offline
              deleelee @PeterJones
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • deleeleeD Offline
                deleelee @PeterJones
                last edited by

                @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!!

                1 Reply Last reply Reply Quote 1

                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
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors