regex - Extracting an array of integers using a regular expression in javascript -


I am having real difficulty with this but I am not a javascript expert. Whatever I want to do, in a string There is an array of all matches that match a given regx. This is regExp:

  [0-9] +  

i.e. Any integer

Then if I pass the string "12 09: 8: 76 ::: 54 12" I should get

arr [0] = "12" arr [1 ARE [3] = "76" ARR [4] = "54" ARR [5] = "12"

Easy? Not for me! I can not make any problems with regexp.matches (string) in vb.net (something like that). I thought the Javascript method EXEC will also give me an array, but it only gives the first match. what's going on? Code ...

  function testIt () {splitOutSelection2 ("123 ::: 45 0 :: 12312 12:17"); } Function splitOutSelection2 (sSelection) {var regExp = new RegExp ("[0-9] +", "g"); Var arr = regExp.exec (sSelection); };  

  arr = ss selection. Match (/ [0-9] + / g);  

g is a global modifier that you need to get all the matches, not just the first one.


Comments