regex on fixed length string, replacing one character



  • I have a text file with a number of entries that are 32 characters in lenght and end with a <
    \w{32}<
    as the search string is working fine to locate them
    What I want to do is inside this string, replace one of the characters with another, so say a 0 with a 5

    Not sure how I need to do to find that to carry the change out

    Thanks in advance



  • @poyntzj

    I think you need to be a bit more specific on what you want to do. Maybe show some concrete examples. It’s probably doable, but to go on the info provided would probably be difficult and maybe wouldn’t get you the real solution you need.



  • @poyntzj said:

    replace one of the characters with another

    If I understand correctly you want to change the character 0 with a 5 ONLY if the line length is EXACTLY 32 characters long with a < following.

    When a problem gets complicated consider breaking it down into steps. At first glance I would:

    1. use the current search string that works to ALSO tag the line with special characters, either at the start or start and end, say possibly a % character.
    2. create another search (replace) regex to ONLY work on the lines with these special characters to replace the 0 with a 5 as your example suggests.

    I hope that gives you an idea.

    Terry


Log in to reply