Hello Folks π
What's up friends, this is SnowBit here. I am young passionate and self-taught developer and have an intention to become successful developer.
Today, I am here with a quick tutorial. So, let's get started.
Extracting year from a string
Let use take a date,
24 February 2006
Now, we have to extract year from the string, so here's how you do it
const extractYear = str => str.match(/\d{4}/)[0];
Works with any layout of date
const extractYear = str => str.match(/\d{4}/)[0];
console.log(extractYear("24 February 2006"))
console.log(extractYear("24-02-2006"))
console.log(extractYear("24/02/2006"))
Try Now,
Thank you for reading, have a nice day!
Your appreciation is my motivation π
- Follow me on Twitter - @codewithsnowbit
- Subscribe to me on YouTube - Code With SnowBit
Top comments (0)