-2

I have some HTML code stored in a variable:

var htmlString = ...

I want to remove all timestamps that are in this string, of the form (example): 2021-04-26 04:15:04.309. Something like:

var htmlStringWithoutTimestamps = removeTimestamps(htmlString)

Hoy can I do this? Maybe with regex?

1 Answers1

0

I've adapted code from another answer. The logic is pretty understandable.

function removeTimestamps(htmlString) {
  var reg = /[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}\.[0-9]{1,3}/g
  return htmlString.replace(reg, "");

}
var htmlString = 'hello 2021-04-26 04:15:04.309! or:AB2021-11-11 11:11:11.222CD'
var htmlStringWithoutTimestamps = removeTimestamps(htmlString)

console.log(htmlStringWithoutTimestamps)
IT goldman
  • 14,885
  • 2
  • 14
  • 28