Community

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

    Replace help

    General Discussion
    5
    18
    61
    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.
    • Gert Beliën
      Gert Beliën last edited by Gert Beliën

      Hi,
      I like some help on a replacement

      If the Line starts with a 2 and position 13-15=998
      Then I want to replace whatever on position 51-54 by 1250.

      Any suggestions?
      Thx in advance,
      gert

      Ekopalypse 1 Reply Last reply Reply Quote 0
      • Ekopalypse
        Ekopalypse @Gert Beliën last edited by

        @Gert-Beliën

        If I’m correct, then this regular expression might do what you are looking for

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

        Alan Kilborn 1 Reply Last reply Reply Quote 2
        • Gert Beliën
          Gert Beliën last edited by

          So that string I have to place in the search.
          What do a place in the replace section?
          maybe stupid question but I’m new to this, so I apologise

          Ekopalypse 1 Reply Last reply Reply Quote 0
          • Ekopalypse
            Ekopalypse @Gert Beliën last edited by Ekopalypse

            @Gert-Beliën

            Yes, replace with 1250 and make sure you have checked regular expression search and put your cursor in the very first position of the document or check wrap aronud

            1 Reply Last reply Reply Quote 2
            • Alan Kilborn
              Alan Kilborn @Ekopalypse last edited by Alan Kilborn

              @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
              • Gert Beliën
                Gert Beliën last edited by

                @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
                • Ekopalypse
                  Ekopalypse last edited by Ekopalypse

                  @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

                  Alan Kilborn 1 Reply Last reply Reply Quote 1
                  • Gert Beliën
                    Gert Beliën last edited by

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

                    1 Reply Last reply Reply Quote 4
                    • Ekopalypse
                      Ekopalypse last edited by

                      @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
                      • Alan Kilborn
                        Alan Kilborn @Ekopalypse last edited by

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

                        Ekopalypse 1 Reply Last reply Reply Quote 1
                        • Ekopalypse
                          Ekopalypse @Alan Kilborn last edited by

                          @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

                          PeterJones Ekopalypse 2 Replies Last reply Reply Quote 1
                          • PeterJones
                            PeterJones @Ekopalypse last edited by

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

                            Alan Kilborn 1 Reply Last reply Reply Quote 2
                            • Alan Kilborn
                              Alan Kilborn @PeterJones last edited by Alan Kilborn

                              @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
                              
                              PeterJones 1 Reply Last reply Reply Quote 1
                              • Ekopalypse
                                Ekopalypse last edited by

                                @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
                                • PeterJones
                                  PeterJones @Alan Kilborn last edited by PeterJones

                                  @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
                                  • Ekopalypse
                                    Ekopalypse last edited by

                                    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

                                    astrosofista 1 Reply Last reply Reply Quote 1
                                    • astrosofista
                                      astrosofista @Ekopalypse last edited by

                                      @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
                                      • Ekopalypse
                                        Ekopalypse @Ekopalypse last edited by Ekopalypse

                                        @Ekopalypse said in Replace help:

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

                                        once again …

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post
                                        Copyright © 2014 NodeBB Forums | Contributors