Community

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

    Replace A if B=C

    Help wanted · · · – – – · · ·
    3
    4
    60
    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.
    • Jaevwyn
      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
      • guy038
        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

        Jaevwyn 1 Reply Last reply Reply Quote 3
        • WinterSilence
          WinterSilence last edited by

          you never grow up if somebody do your work

          1 Reply Last reply Reply Quote 1
          • Jaevwyn
            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
            • First post
              Last post
            Copyright © 2014 NodeBB Forums | Contributors