[Solved] Javascript Array – Split string at numbers [closed]


use a character class to split the values:

/(-?[\d.]+)/
  • -? May start with a negative such as -123
  • [\d.]+ Has one or more numbers and decimals
var string = "stuff 1.23! (456) 789 stuff -234".split(/(-?[\d.]+)/);

console.log(string)

solved Javascript Array – Split string at numbers [closed]