I have a string like this…
"1.first. 2.second. 3.third"
and I want it to be like this using JavaScript split
["1.first.", "2.second", "3.third"]
I saw C# is like this Regex.Split(txt, "[0-9]+\.");
but I need it in JavaScript, please help
I try using this…
description.split(/([0-9]+)/)
but it turn out to be like this
[
"1",
". first",
"2",
". second ",
"3",
".third",
"23",
"two three",
"4",
".four"
]
2
Answers
Just split with
' '
:If you could have trailing or several spaces between words – match words (non white space characters) with
S+
in a regex:For splitting your string into an array, try this snippet of JavaScript code:
This will neatly turn your string into [‘1.first.’, ‘2.second.’, ‘3.third’].