Extract numbers from a string using javascript
问题 I'd like to extract the numbers from the following string via javascript/jquery: "ch2sl4" problem is that the string could also look like this: "ch10sl4" or this "ch2sl10" I'd like to store the 2 numbers in 2 variables. Is there any way to use match so it extracts the numbers before and after "sl" ? Would match even be the correct function to do the extraction? Thx 回答1: Yes, match is the way to go: var matches = str.match(/(\d+)sl(\d+)/); var number1 = Number(matches[1]); var number2 = Number