Jquery get substring between parenthesis

2019-09-04 11:53发布

I have string like

"Shabalu Sheedaa - Ali Gul Panara - Octa School - 10 (7)"

and I want to extract the value between parenthesis using jquery. In this case it will be 7.

1条回答
聊天终结者
2楼-- · 2019-09-04 12:35

Try:

var regExp = /\(([^)]+)\)/;
var matches = regExp.exec("Shabalu Sheedaa - Ali Gul Panara - Octa School - 10 (7)");

//matches[1] contains the value between the parentheses
console.log(matches[1]);

Explation of Reg Exp:

Breakdown:

\( : match an opening parentheses
( : begin capturing group
[^)]+: match one or more non ) characters
) : end capturing group
\) : match closing parentheses
查看更多
登录 后发表回答