jQuery获取括号之间的子字符串 [英] Jquery get substring between parenthesis

查看:840
本文介绍了jQuery获取括号之间的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似的字符串

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

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

,我想使用jquery提取括号之间的值. 在这种情况下,它将是7.

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

推荐答案

尝试:

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]);

Reg Exp的到期时间:

Explation of Reg Exp:

Breakdown:

\( : match an opening parentheses
( : begin capturing group
[^)]+: match one or more non ) characters
) : end capturing group
\) : match closing parentheses

这篇关于jQuery获取括号之间的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆