Community
    • Login

    Why is it that some regex match is not replaced one by one?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 285 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 Former User
      last edited by

      I am using notepad++ for text editing.

      sample text : hello,this is a test.are you ready?

      search for : (?<=[a-z,.?! ])([,.?!])(?=[a-z])

      replace with : \1

      replace result : hello, this is a test. are you ready?

      It works as intended, only if I replace them all, but if I click on replace button, nothing happens. It navigates to the next match as if I click on find.

      refer to this screenshot [https://i.stack.imgur.com/4CiPY.png]

      Is it a bug and what’s the solution I should try?

      Thank you!

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @A Former User
        last edited by PeterJones

        @[username redacted] ,

        Any regex that uses \K match-resets or (?<=...) / (?<!...) lookbehinds require using replace all rather than single replace actions. That’s the way it was designed, to avoid certain …confusions… that would arise with reset- and lookbehind- replacements run one-at-a-time.

        1 Reply Last reply Reply Quote 1
        • ?
          A Former User
          last edited by

          thanks for the reply. maybe this is the alternative I can think of.

          ([a-z,.?! ][,.?!])(?=[a-z])

          it’s not perfect, but it does the job anyway :)
          only downside is it matches preceding characters as well, so it looks less charming.

          1 Reply Last reply Reply Quote 1
          • ?
            A Former User
            last edited by A Former User

            can I ask one more for troubleshooting?
            I wonder if I could open the document and remember the last scroll position so next time I reopen it, it straight nagivgates to where it was.

            PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @A Former User
              last edited by PeterJones

              @[username redacted]

              remember the last scroll position

              if you close/exit Notepad++ and reload the application, it does remember the scroll position for the active session. But no, once you close the document, it loses that scroll information.

              1 Reply Last reply Reply Quote 1
              • Alan KilbornA
                Alan Kilborn @A Former User
                last edited by PeterJones

                @[username redacted] said in Why is it that some regex match is not replaced one by one?:

                I wonder if I could open the document and remember the last scroll position so next time I reopen it, it straight nagivgates to where it was.

                You may find THIS to be of interest on that topic. There’s a Pythonscript there that supposedly solves this “problem”. I haven’t tried the script out yet, so I can’t fully endorse it. It’s on my evergrowing “TODO” list. :-)

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors