Community
    • Login

    Conditional replacing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 511 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.
    • William BaldwinW
      William Baldwin
      last edited by

      So I have a document that will have a number for each member number we will say its 1234567 (always the same base member number)
      about 6 rows below that will be a row it will find a identifier like PRM or SEL
      I want it to then go back to that member number and add (replace to 123456789) 89 to the member number if is identifies PRM, else if it is SEL then I want it to add (replace to 123456700) 00 to the member number. Ideas?

      astrosofistaA 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by

        There is conditional syntax in regex (both in match and replacement), so it’s not impossible.

        But to be helpful, we would need dummy data. Please show us something that would be representative of the actual data (but of course no sensitive info), and preferrably show us both a before and an after set of data.

        To include the data in your post, paste it in, highlight it, and use the </> button on the toolbar:
        b9aa1100-d3b5-44fa-a79b-408c6c56e030-image.png
        Keep the data separate, like
        BEFORE:

        here is data
        

        AFTER:

        there went my data. whoops.
        
        1 Reply Last reply Reply Quote 1
        • astrosofistaA
          astrosofista @William Baldwin
          last edited by

          Hi @William-Baldwin, @PeterJones

          This regex could do the job, but lacking of actual data, as @PeterJones noted, may make it fail. Take it as a proof of concept:

          1234567
          bla
          bla
          bla
          bla
          bla
          PRM
          1234567
          bla
          bla
          bla
          bla
          bla
          SEL
          

          Search: (?-s)^(\d{7})(?s).*?(?:(PRM)|(SEL))
          Replace: (?2${1}89)(?3${1}00)

          Output:

          123456789
          123456700
          

          Hope this helps.

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