Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a string starts with a number in parentheses

My title can look like

(10) - lorem ipsum
(101) - lorem ipsum
(1) - lorem ipsum
lorem ipsum

I want to check if my title contains (number) at the start

string.match(/^(+[0-9]+)+$/);

I'm not good on regex, can someone help and say what is wrong ?

like image 568
Wizard Avatar asked Mar 14 '23 03:03

Wizard


1 Answers

Just remove the $ from your regex, and escape the parentheses.

string.match(/^\([0-9]+\)/);

$ means end of string.

( and ) are special character and should be escaped. Pharenthesis are used for grouping. You can find a list of special characters here.

like image 164
Adam Avatar answered Mar 24 '23 04:03

Adam