I have strings such as
(123)abc
defg(456)
hijkl
(999)
7
I want to match these strings one at a time with a regular expression to extract any number from the string where the string starts with a '(' has a number in between and then a ')' followed by zero or more characters. So, in the above 5 examples I would match 123 in the first case, nothing in the second and third case, 999 in the fourth case and nothing in the fifth case.
I have tried this
var regex = new RegExp("^\((\d+)\)", "gm");
var matches = str.match(regex);
But matches always comes out as null. What am I doing wrong?
I have tried this regex at regex101 and it seems to work so I am at a loss why the code doesn't work.
RegExpconstructor, you'll need to provide escape sequences for both the pattern and the string literal --new RegExp("^\\((\\d+)\\)", "gm").