I’m looking for something in JS that could help me identify when a set of numbers begins and ends(by a space or other character that is not a number or letter).
For example: let’s say the user inputs – 2424+345 (yes I’m building a calculator). I want to identify when the number starts and ends (ends when the + sign starts). Then it saves it as a variable for later use and continues reading the second set of numbers and assigns it to a variable as well. I can loop through the input, but what I don’t know is how to write the rule that does all the checking and assigning.
Regex seems to be the way to go, but I have very little experience with it (have done some simple form validation with it).
To find the first number in a string, the regular expression would be
/^\d+/, so for instance:Put that in a loop, consuming the operators…