• Login
Community
  • Login

Replace A if B=C

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 228 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.
  • J
    Jaevwyn
    last edited by Jul 13, 2020, 10:51 AM

    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
    • G
      guy038
      last edited by Jul 13, 2020, 11:49 AM

      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

      J 1 Reply Last reply Jul 14, 2020, 6:39 AM Reply Quote 3
      • W
        WinterSilence
        last edited by Jul 13, 2020, 2:24 PM

        you never grow up if somebody do your work

        1 Reply Last reply Reply Quote 1
        • J
          Jaevwyn @guy038
          last edited by Jul 14, 2020, 6:39 AM

          @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
          2 out of 4
          • First post
            2/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors