Skip to content

Instantly share code, notes, and snippets.

@aman-gautam
Created August 23, 2022 16:37
Show Gist options
  • Save aman-gautam/c188c98ac5ea774c17493d8f378aa929 to your computer and use it in GitHub Desktop.
Save aman-gautam/c188c98ac5ea774c17493d8f378aa929 to your computer and use it in GitHub Desktop.
function parseTime(str) {
const matches = str.match(/([0-9])\w*:([0-9])\w*/g);
matches.forEach(match => {
const split = match.split(':')
const seconds = parseInt(split[0]) * 60 + parseInt(split[1]);
console.log(match);
str = str.replaceAll(match, `<a href="https://youtu.be/I-A74HbCyK4?t=${seconds}">${match}</a>`)
})
return str;
}
parseTime(`1:00 RegExr was created by gskinner.com, and is proudly hosted by Media Temple.
Edit the Expression 3:00 1:12& Text to see matches. Roll over matches or the expression for details. PCRE & JavaScript flavors of RegEx are supported. Validate your expression with Tests mode.
The side bar includes a 2:00 Cheatsheet, full Reference, and Help. You can also Save & Share with the Community, and view patterns you create or favorite in My Patterns.
Explore results with the Tools below. Replace & List output custom results. Details lists capture groups. Explain describes your expression in plain English.`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment