• Login
Community
  • Login

Notepad Search and repalce - help

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 3 Posters 534 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.
  • J
    John Praveen Kumar R
    last edited by John Praveen Kumar R Oct 22, 2020, 9:11 AM Oct 22, 2020, 9:10 AM

    Dear All

    I need to search a File which has got messages and wanted to replace a specific character in the line

    if in the line - it should search for “{1:F01” and replace the 8 character After “01” to something else and again search if something starts with “{2:I” and replace 11th charcter after “I” and should be repeated for entire file

    1 Reply Last reply Reply Quote 0
    • L
      litos81
      last edited by litos81 Oct 22, 2020, 9:37 AM Oct 22, 2020, 9:35 AM

      Hi @John-Praveen-Kumar-R

      The following expressions could work for if I understood what you need:
      Find what: ({1:F01.{7})(.{1})
      Replace: $1[your_replacement]
      and
      Find what: ({2:I.{10})(.{1})
      Replace: $1[your_replacement]

      As you can see the expression is ([your_characters_to_search].{n-1})(.{1}) where n is the position of the character you want to replace.

      Don’t forget to select te ‘Regular expression’ mode in the Replace dialog.

      If it doesn’t work, could you please add an actual example of your text before and after the changes?

      1 Reply Last reply Reply Quote 3
      • J
        John Praveen Kumar R
        last edited by John Praveen Kumar R Oct 22, 2020, 9:52 AM Oct 22, 2020, 9:51 AM

        @litos81 said in Notepad Search and repalce - help:

        ({1:F01.{7})(.{1})

        Thank you very much. Find is working perfectly - Replace is replacing with [] brackets. I just need that charcter to be replaced

        1 Reply Last reply Reply Quote 0
        • L
          litos81
          last edited by litos81 Oct 22, 2020, 9:58 AM Oct 22, 2020, 9:58 AM

          @John-Praveen-Kumar-R said in Notepad Search and repalce - help:

          Replace is replacing with [] brackets.

          Sorry, I put brackets in my answer and it is very confusing, you don’t actually need them. Just change your replacement to: $1your_replacement, the same goes for the Search expression, it doesn’t need the []:
          Search:(your_characters_to_search.{n-1})(.{1})

          1 Reply Last reply Reply Quote 2
          • J
            John Praveen Kumar R
            last edited by Oct 22, 2020, 10:04 AM

            Replacing with a alphabet is fine. I want to replace with value 0

            1 Reply Last reply Reply Quote 0
            • L
              litos81
              last edited by litos81 Oct 22, 2020, 10:18 AM Oct 22, 2020, 10:18 AM

              I see. You can then replace the search expression for this one:
              Find what: (?<=characters_to_search.{n-1})(.{1})
              Replace with: your_replacement

              The new expression makes use of a ‘positive lookbehind’ expression. From the notepad++ manual (https://npp-user-manual.org/docs/searching/#assertions ):
              (?<=pattern) ⇒ positive lookbehind: This assertion matches if pattern matches before the current token.

              1 Reply Last reply Reply Quote 2
              • J
                John Praveen Kumar R
                last edited by Oct 23, 2020, 9:52 AM

                Sorry this is throwing an error

                My text is

                {F01QNbaqaqaxxxxxxxxxx} {2:I03bnorphmmxxxn}

                I wanted to replace QNBAQAQA TO QNBAQAQ0 AND THE {2:… Will vary for each line. I wanted to replace 8 th character after 3 which is m to 0

                I wanted to replace the 8th.character after F01 to 0 and 8gh character after 2:I03 to 0

                P 1 Reply Last reply Oct 23, 2020, 1:13 PM Reply Quote 0
                • P
                  PeterJones @John Praveen Kumar R
                  last edited by Oct 23, 2020, 1:13 PM

                  @John-Praveen-Kumar-R

                  The following advice will help you make your requests for help easier to understand:

                  Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as plain text using the </> toolbar button or manual Markdown syntax. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get… Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

                  1 Reply Last reply Reply Quote 1
                  • L
                    litos81
                    last edited by Oct 23, 2020, 1:54 PM

                    @John-Praveen-Kumar-R said in Notepad Search and repalce - help:

                    Sorry this is throwing an error

                    @John-Praveen-Kumar-R What is the actual error?

                    If I understood correctly your descriptions in your last post I’d recommend to do the replacement in 2 steps:
                    Find what: (?<={F01.{7})(.{1})
                    Replace with: 0
                    and
                    Find what: (?<={2:I03.{7})(.{1})
                    Replace with: 0

                    If it doesn’t solve your problem, please follow @PeterJones advice so that we can understand better your case.

                    1 Reply Last reply Reply Quote 2
                    • J
                      John Praveen Kumar R
                      last edited by Oct 23, 2020, 3:47 PM

                      Thanks a Lot. This works fine.

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