Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Sort ignoring leading 'the'

    Help wanted · · · – – – · · ·
    2
    6
    121
    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.
    • deleelee
      deleelee last edited by

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

      PeterJones 1 Reply Last reply Reply Quote 0
      • PeterJones
        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|...)

        deleelee 1 Reply Last reply Reply Quote 2
        • deleelee
          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.

          PeterJones 1 Reply Last reply Reply Quote 0
          • PeterJones
            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)

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

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • deleelee
                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
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors