Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    regex on fixed length string, replacing one character

    Help wanted · · · – – – · · ·
    3
    3
    651
    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.
    • poyntzj
      poyntzj last edited by

      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

      Alan Kilborn 1 Reply Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @poyntzj last edited by

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

        1 Reply Last reply Reply Quote 3
        • Terry R
          Terry R last edited by

          @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

          1 Reply Last reply Reply Quote 2
          • First post
            Last post
          Copyright © 2014 NodeBB Forums | Contributors