Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How split the months from a string?

I need to split only month names from a string .

Ex :

let str = "januaryfebruaryapriltuesdayfriday";

I want to split like

let arr = ["january","february"," april "]

I am new to JS , I have tried split method ,but i didn't get the result ,is there anyway to do this ?

like image 665
parithi info Avatar asked Feb 06 '26 04:02

parithi info


1 Answers

You could use a regular expression for searching for month names and get an array of it.

var string = "januaryfebruaryapriltuesdayfriday",
    array = string.match(/january|february|march|april|may|june|july|august|september|october|november|december/gi);
    
console.log(array);
like image 85
Nina Scholz Avatar answered Feb 07 '26 17:02

Nina Scholz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!