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
TillNumberattribute is changed by the number91ONLY IF the value of theStartDateattribute is prior to the date2020-04-01If so, the following regex S/R should work :
SEARCH
\d+(?=</TillNumber>\R.+\R<StartDate>(19\d\d|20[01]\d|2020\-0[123]))REPLACE
91Of course, select the
Regular expressionsearch mode and, may be, theWrap aroundoptionBest 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
TillNumberattribute is changed by the number91ONLY IF the value of theStartDateattribute is prior to the date2020-04-01If so, the following regex S/R should work :
SEARCH
\d+(?=</TillNumber>\R.+\R<StartDate>(19\d\d|20[01]\d|2020\-0[123]))REPLACE
91Of course, select the
Regular expressionsearch mode and, may be, theWrap aroundoptionBest Regards,
guy038
Perfect, thanks!
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