I have long string like
"When I was 10 year old"
I have to get this string split to an array: ["When I was", "10" , "year old"]
.
The integer can be different in different cases and the sentence may also change.
In short i want to split a string by integer in it Is it possible?
How can i use regex in conjugation with split in Jquery/java-script
You can use
var str = "When I was 10 year old";
var arr = str.match(/(\D*)\s(\d*)\s(\D*)/).slice(1);
Result :
["When I was", "10", "year old"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With