Community
    • Login

    Replace A if B=C

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 458 Views 1 Watching
    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.
    • JaevwynJ Offline
      Jaevwyn
      last edited by

      Hi,

      Not really sure how to phrase my query but here goes!
      I am trying to run a replace on an XML formatted as below:

      <TxnHeader>
      <StoreId>XXXX</StoreId>
      <TillNumber>1</TillNumber>
      <TxnNumber>XXXX</TxnNumber>
      <StartDate>2020-03-19T13:12:15</StartDate>
      <TxnType>X</TxnType>
      </TxnHeader>

      There are thousands of these in the file, all of which have a much longer set of details for the lines of the transactions (this is just a view of the transaction header), and I need to replace the Till Number with 91 for every one of these that has a hade in march (2020-03).

      I am sure its possible with a RegEx but have no skills past simple find and replaces, hoping someone here can help!

      1 Reply Last reply Reply Quote 0
      • guy038G Online
        guy038
        last edited by

        Hi, @jaevwyn and All,

        If I correctly understood you, you want that the value of the TillNumber attribute is changed by the number 91 ONLY IF the value of the StartDate attribute is prior to the date 2020-04-01

        If so, the following regex S/R should work :

        SEARCH \d+(?=</TillNumber>\R.+\R<StartDate>(19\d\d|20[01]\d|2020\-0[123]))

        REPLACE 91

        Of course, select the Regular expression search mode and, may be, the Wrap around option

        Best Regards,

        guy038

        JaevwynJ 1 Reply Last reply Reply Quote 3
        • WinterSilenceW Offline
          WinterSilence
          last edited by

          you never grow up if somebody do your work

          1 Reply Last reply Reply Quote 1
          • JaevwynJ Offline
            Jaevwyn @guy038
            last edited by

            @guy038 said in Replace A if B=C:

            Hi, @jaevwyn and All,

            If I correctly understood you, you want that the value of the TillNumber attribute is changed by the number 91 ONLY IF the value of the StartDate attribute is prior to the date 2020-04-01

            If so, the following regex S/R should work :

            SEARCH \d+(?=</TillNumber>\R.+\R<StartDate>(19\d\d|20[01]\d|2020\-0[123]))

            REPLACE 91

            Of course, select the Regular expression search mode and, may be, the Wrap around option

            Best Regards,

            guy038

            Perfect, thanks!

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors