1

This is both a question and an answer so that the next time I encounter this bug and Google for an answer, I'll find it here.

The output of

Intl.DateTimeFormat('en-US', {
  year: 'numeric',
  month: 'numeric',
  day: 'numeric',
  hour: 'numeric',
  minute: 'numeric',
  second: 'numeric',    
})

Is like 3/7/2020 6:43:00 AM in IE11. It looks like this regex (please do not judge my regex skills):

/:[0-9]{2}:[0-9]{2}/g

Should match the :43:00 portion, and it does in other browsers. But it does not in IE11. What gives?

nabrown
  • 827
  • 10
  • 15
  • @RobG This seems related but not a duplicate. The other q/a you linked to is helpful, but not for Javascript. I looked for a similar regex entity to `\p{Cf}` for javascript implementations but did not find one. – nabrown Apr 03 '20 at 14:04
  • Duplicate of [*IE's toLocaleString has strange characters in results*](https://stackoverflow.com/questions/25574963/ies-tolocalestring-has-strange-characters-in-results). Other useful questions: [*ToLocaleDateString() changes in IE11*](https://stackoverflow.com/questions/21413757/tolocaledatestring-changes-in-ie11), [*Strip consecutive line breaks from contenteditable*](https://stackoverflow.com/questions/45269759/strip-consecutive-line-breaks-from-contenteditable) – RobG Apr 04 '20 at 22:53

1 Answers1

0

The output from IE11 contains invisible left-to-right markers (\u200E) causing the regex to not match.

My solution was to remove these first, before trying to do anything with the string:

myDateTimeStr.replace(/\u200E/g, '')

I got the clue from this issue report on react-intl.

RobG
  • 142,382
  • 31
  • 172
  • 209
nabrown
  • 827
  • 10
  • 15