• Login
Community
  • Login

Replace help

Scheduled Pinned Locked Moved General Discussion
18 Posts 5 Posters 662 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.
  • A
    Alan Kilborn @Ekopalypse
    last edited by Alan Kilborn Mar 5, 2021, 3:04 PM Mar 5, 2021, 3:02 PM

    @Ekopalypse said in Replace help:

    (?<=^2.{11}998.{34}).{4}

    Is there a one-off problem here?
    I see this matching positions (one-based) 50-53, not 51-54.
    Or maybe it’s me.
    If it IS wrong, let’s see if OP is savvy enough to see the patterns in the expression and correct it himself. :-)

    EDIT: Guess it was me as the OP is happy (see post below). Disregard!!

    1 Reply Last reply Reply Quote 2
    • G
      Gert Beliën
      last edited by Mar 5, 2021, 3:03 PM

      @Ekopalypse said in Replace help:

      (?<=^2.{11}998.{34}).{4}

      I don’t understand but hey “It works” :-)
      Thank you very much @Ekopalypse

      1 Reply Last reply Reply Quote 1
      • E
        Ekopalypse
        last edited by Ekopalypse Mar 5, 2021, 3:24 PM Mar 5, 2021, 3:23 PM

        @Alan-Kilborn

        you are right. I’m one off.
        So the correct regex would be (?<=^2.{11}998.{35}).{4}

        I am still confused by the fact that the position as shown in the statusbar no longer starts at 0.

        @Gert-Beliën
        Could it be that we both had a off by one issue? :-D

        A 1 Reply Last reply Mar 5, 2021, 3:31 PM Reply Quote 1
        • G
          Gert Beliën
          last edited by Mar 5, 2021, 3:24 PM

          I needed indeed .{35} to make it work but that I found out myself -:)

          1 Reply Last reply Reply Quote 4
          • E
            Ekopalypse
            last edited by Mar 5, 2021, 3:30 PM

            @Gert-Beliën

            Great :-)

            A short explanation what the regex does,
            it is using a lookbehind (?<=...) for the condition to match .{4}

            ^ means start of line
            2
            .{11} any character but 11 times
            998
            .{35} any character but 35 times

            So basically it means the line has to start with 2, followed by 11 characters, followed by 998, followed by 35 characters and then match the next 4 characters.
            Lookbehind can only be used with a fixed length term to search, which was the case here. :-)

            1 Reply Last reply Reply Quote 1
            • A
              Alan Kilborn @Ekopalypse
              last edited by Mar 5, 2021, 3:31 PM

              @Ekopalypse said in Replace help:

              I am still confused by the fact that the position as shown in the statusbar no longer starts at 0.

              You mean the Pos: thing?
              It’s relatively new, right?
              But I believe it has always been “one based”, never “zero based”.

              (I wish it was zero-based, as that would help when writing my PythonScripts – Scintilla always deals with zero-based positions)

              E 1 Reply Last reply Mar 5, 2021, 3:32 PM Reply Quote 1
              • E
                Ekopalypse @Alan Kilborn
                last edited by Mar 5, 2021, 3:32 PM

                @Alan-Kilborn said in Replace help:

                But I believe it has always been “one based”, never “zero based”.

                Really, I’m getting old and confused :-D

                P E 2 Replies Last reply Mar 5, 2021, 3:37 PM Reply Quote 1
                • P
                  PeterJones @Ekopalypse
                  last edited by Mar 5, 2021, 3:37 PM

                  @Ekopalypse said in Replace help:

                  @Alan-Kilborn said in Replace help:

                  But I believe it has always been “one based”, never “zero based”.

                  Really, I’m getting old and confused :-D

                  I’ve always just added a line like

                  123456789x123456789x123456789x123456789x123456789x123456789x123456789x123456789x
                  

                  when I’m answering positional-based requests, That method works in any version of Notepad++ and doesn’t make me think about 0-based vs 1-based. :-)

                  A 1 Reply Last reply Mar 5, 2021, 3:40 PM Reply Quote 2
                  • A
                    Alan Kilborn @PeterJones
                    last edited by Alan Kilborn Mar 5, 2021, 3:42 PM Mar 5, 2021, 3:40 PM

                    @PeterJones said in Replace help:

                    I’ve always just added a line like

                    Ha! I did that too!:

                    bf679ad0-beaa-4454-ac82-e2b7d7e5dd4c-image.png

                    (RegexBuddy pictured)

                    This, in N++ is even handier, but I can’t find where I’ve put it quickly enough sometimes:

                    123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-
                             10        20        30        40        50        60        70        80        90       100
                    
                    P 1 Reply Last reply Mar 5, 2021, 3:44 PM Reply Quote 1
                    • E
                      Ekopalypse
                      last edited by Mar 5, 2021, 3:42 PM

                      @Alan-Kilborn @PeterJones

                      Lazy as I’m I looked at the statusbar until I saw 50(thinking it must be 51 because scintilla start from 0) and then selected the dots - which was obviously wrong.

                      c9e47f02-981c-4158-86db-5ca8f48f6383-image.png

                      1 Reply Last reply Reply Quote 2
                      • P
                        PeterJones @Alan Kilborn
                        last edited by PeterJones Mar 5, 2021, 3:44 PM Mar 5, 2021, 3:44 PM

                        @Alan-Kilborn said in Replace help:

                        This, in N++ is even handier, but I can’t find where I’ve put it quickly

                        I find it’s faster to re-create than to store in some useful copy-and-paste location. Typing the 10 characters, then duplicating 8+ times, is pretty fast (and almost in my muscle memory now).

                        I suppose we could create macros to insert those. :-)

                        1 Reply Last reply Reply Quote 1
                        • E
                          Ekopalypse
                          last edited by Mar 5, 2021, 3:47 PM

                          Yeah, we could. Maybe I should have written a python script to do it :-)

                          And now the question, why were the first dots correct? I counted them. :-D

                          A 1 Reply Last reply Mar 5, 2021, 7:29 PM Reply Quote 1
                          • A
                            astrosofista @Ekopalypse
                            last edited by Mar 5, 2021, 7:29 PM

                            @Ekopalypse, @Alan-Kilborn, @PeterJones

                            Actually there is a Python script for it. In my configuration is at

                            “D:\Applications\npp.7.9.1.portable.x64\plugins\PythonScript\scripts\Samples\InsertRuler.py ”

                            For learning purposes I replicated most of it in AutoHotkey, but I rarely use any of both.

                            Take care and have fun!

                            1 Reply Last reply Reply Quote 2
                            • E
                              Ekopalypse @Ekopalypse
                              last edited by Ekopalypse Mar 5, 2021, 7:31 PM Mar 5, 2021, 7:31 PM

                              @Ekopalypse said in Replace help:

                              Really, I’m getting old and confused :-D

                              once again …

                              1 Reply Last reply Reply Quote 0
                              14 out of 18
                              • First post
                                14/18
                                Last post
                              The Community of users of the Notepad++ text editor.
                              Powered by NodeBB | Contributors