oussama kamal oussama kamal - 6 days ago 5
Javascript Question

Split and add <br> tag to concatenated dates in Javascript

I have a string in javascript that looks like: 11/25/1612/02/1612/09/1606/03/17
The string can have many dates concatenated.

How can I place an HTML
tag between each date of that string so that the output will be 11/25/16 br 12/02/16 br 12/09/16 br 06/03/17

Thanks

Answer

Use String#replace method.

console.log(
  '11/25/1612/02/1612/09/1606/03/17'.replace(/(?:\d{2}\/){2}\d{2}(?!$)/g, '$&<br>')
);

Comments