Replace A if B=C
-
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!
-
Hi, @jaevwyn and All,
If I correctly understood you, you want that the value of the
TillNumber
attribute is changed by the number91
ONLY IF the value of theStartDate
attribute is prior to the date2020-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, theWrap around
optionBest Regards,
guy038
-
you never grow up if somebody do your work
-
@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 number91
ONLY IF the value of theStartDate
attribute is prior to the date2020-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, theWrap around
optionBest Regards,
guy038
Perfect, thanks!