This JS regex error is killing me - one correct match out of three and one false match.
If it makes a difference I am writing my script in Google Apps Script.
I have a string (xml formatted) I want to match three date nodes as follows:
<dateCreated>1619155581543</dateCreated>
<dispatchDate>1619478000000</dispatchDate>
<deliveryDate>1619564400000</deliveryDate>
I don't care about the tags so much - I just need enough to reliably replace them. I am using this regular expression:
var regex = new RegExp('[dD]ate(.{1,})?>[0-9]{13,}</');
These are the matches:
dateCreated>1619155581543</
Created
Obviously I understand number 1 - I wanted that. But I do not understand how 2 was matched. Also why were dispatchDate
and deliveryDate
not matched? All three targets are matched if I use the above regex in BBEdit and on https://ihateregex.io/playground and neither of those match "Created".
I've also tried this regular expression without success:
var regex = new RegExp('[dD]ate.{0,}>[0-9]{13,}</');
If you can't answer why my regex fails but you can offer a working solution I'd still be happy with that.