• Login
Community
  • Login

RegEx selective replace

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 300 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.
  • F
    Forum Bloke
    last edited by Jul 14, 2020, 3:43 PM

    Hi

    I’m hoping someone can help as I’ve been struggling with this all day!

    I have some text files that I want to do some search/replace on but I can’t work out how to reference selectively what I’m trying to replace.

    Taking this as the test:

    IF Thirty THEN
    DRAW("               Twenty, Thirty, Forty, Fifty")
    ENDIF
    

    I would like to replace the Thirty on line that includes DRAW with ‘30’ but not on the IF line. How can I do this please.

    I’m tearing my hair out!

    Many thanks

    Rob

    P 1 Reply Last reply Jul 14, 2020, 3:50 PM Reply Quote 0
    • P
      PeterJones @Forum Bloke
      last edited by Jul 14, 2020, 3:50 PM

      @Forum-Bloke ,

      • FIND WHAT = (?-s)(DRAW.*)Thirty
      • REPLACE WITH = $1Replacement
      • MODE = regular expression

      Requires DRAW to come before the Thirty, on the same line.

      • (?-s) = dot wildcard does not match space
      • (DRAW.*) = literal text DRAW followed by 0 or more characters (.*), all put into group#1
      • Thirty = literal text you want to replace
      • $1 = in the replacement, this will include the contents of group#1, which is everything from DRAW (including the DRAW) to just before the Thirty
      • Replacement = the word you want to insert instead of Thirty

      ----
      Official Notepad++ Searching/Regex Docs = https://npp-user-manual.org/docs/searching/#regular-expressions

      1 Reply Last reply Reply Quote 2
      • F
        Forum Bloke
        last edited by Jul 14, 2020, 4:42 PM

        @PeterJones said in RegEx selective replace:

        (?-s)(DRAW.*)Thirty

        Many thanks!

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