Community
    • Login

    Find and Replace with Regular Expressions (Regex): Software error or inadequate user? :-)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 1.1k 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.
    • Danilo SchembriD
      Danilo Schembri
      last edited by

      Hi,

      I have this text:
      FIELD ONE
      FIELD TWO
      FIELD THREE

      I want to replace “spaces” with “underscores”, but only when the “space” is only one and between words.

      I use this Regex:
      Find: ([A-Z]) ([A-Z])
      Replace: \1_\2

      If I use buttons with the sequence
      Find, Repl&FAgain (1), Repl&FAgain (1), Repl&FAgain (1)
      I obtain a strange substitution
      FIELD_ONE
      FIEL_WO
      FIEL_HREE

      Instead of
      FIELD_ONE
      FIELD_TWO
      FIELD_THREE

      It works with button sequence
      Find, Replace Rest
      or
      Find, Repl&FAgain (3)

      Is it a bug or I misunderstood anything?

      Danilo

      Meta ChuhM 1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello, @Danilo Schembri and All,

        Ah, you spoke of the TextFX plugin behavior ! Seemingly, when doing a step by step replacement, it does not update the values of group 1 and group 2, leaving them empty :-((

        But, why don’t you perform the native N++ replacement, instead ?

        • Open the Replace dialog ( CTRL + H )

        • SEARCH ([A-Z])\x20([A-Z])

        • REPLACE \1_\2

        • Select the Regular expression` search mode

        • Tick , if necessary, the Wrap around option

        • Click, once, on the Replace All OR several times on the Replace button

        You may use a simple space character, instead of the \x20 syntax

        Best Regards

        guy038

        1 Reply Last reply Reply Quote 1
        • Meta ChuhM
          Meta Chuh moderator @Danilo Schembri
          last edited by

          @Danilo-Schembri

          your regex works for me

          Find: ([A-Z]) ([A-Z])
          Replace: \1_\2
          `Search Mode: Regular Expression

          gives me

          FIELD_ONE
          FIELD_TWO
          FIELD_THREE

          if i press replace all (or repeatedly press replace)

          @guy038
          i think you ment:
          REPLACE \1\x5F\2 instead of REPLACE \1\x20\2

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