Notepad Search and repalce - help



  • 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



  • 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?



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



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



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



  • 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.



  • 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



  • @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.



  • @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.



  • Thanks a Lot. This works fine.


Log in to reply