Here is a string: (1 AND 2) OR 30 AND (4 AND 5). I need a list of numbers included in this string. Please help me out.
1 Answer
Use match:
var numbers = "(1 AND 2) OR 30 AND (4 AND 5)"
var formatted = numbers.match(/\d+/g)
console.log(formatted); // [1,2,30,4,5]
3 Comments
abhimanyu singh rathore
Hey @jonathandion, I need 30, not 3 and 0 separately.
Jonathan Dion
I updated my answer.
Jonathan Dion
If the answer is good you should accept it to close the question. Thanks.