-2

Suppose I have this text :

qsdfq fmld - 123 -mqlskdj -6464  - qlsdkjflj - 54654 -qsdfqsdf -2542

And I want to capture all numbers. A solution could be :

\D*(\d*)\D*(\d*)\D*(\d*)\D*(\d*)

But I don't know how many numbers I have. So I want to use the + sign. I tried the following but it does not work :

[\D*(\d*)]+
G F
  • 321
  • 1
  • 5
  • 12

1 Answers1

1

You can simply use \d+ and global flag ( g )

let str = `qsdfq fmld - 123 -mqlskdj -6464  - qlsdkjflj - 54654 -qsdfqsdf -2542`
let op = str.match(/\d+/g)

console.log(op)

On side note: I have JS code just to show a working example.

Code Maniac
  • 37,143
  • 5
  • 39
  • 60