Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete data by mask in Javascript using .replace or something else?

I’m getting data in the form of date and time:

Monday Jan 23 10:14:27 2024

How in Javascript using .replace to remove everything except time without seconds:

10:14

.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please tell me, because I am already lost in these regular expressions.
Thank you all.

>Solution :

Use String.prototype.match

const reg = /\d{2}:\d{2}/
const str = 'Monday Jan 23 10:14:27 2024'
const time = str.match(reg)[0]
console.log(time)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading