• Login
Community
  • Login

Sort ignoring leading 'the'

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 564 Views
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.
  • D
    deleelee
    last edited by Oct 28, 2022, 10:10 PM

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

    P 1 Reply Last reply Oct 28, 2022, 10:55 PM Reply Quote 0
    • P
      PeterJones @deleelee
      last edited by PeterJones Oct 28, 2022, 10:57 PM Oct 28, 2022, 10:55 PM

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

      D 1 Reply Last reply Oct 29, 2022, 12:36 AM Reply Quote 2
      • D
        deleelee @PeterJones
        last edited by Oct 29, 2022, 12:36 AM

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

        P 1 Reply Last reply Oct 29, 2022, 12:42 AM Reply Quote 0
        • P
          PeterJones @deleelee
          last edited by PeterJones Oct 29, 2022, 12:44 AM Oct 29, 2022, 12:42 AM

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

          D 2 Replies Last reply Oct 29, 2022, 12:46 AM Reply Quote 0
          • D
            deleelee @PeterJones
            last edited by Oct 29, 2022, 12:46 AM

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • D
              deleelee @PeterJones
              last edited by Oct 29, 2022, 1:00 AM

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