【问题标题】:Jquery get substring between parenthesisjQuery获取括号之间的子字符串
【发布时间】:2016-08-30 01:08:00
【问题描述】:

我有类似的字符串

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

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

【问题讨论】:

  • 这已被询问了 178434 次。 string.match(/\(\d+\)/)[0]
  • 这不是 jquery 的问题

标签: javascript jquery string substring


【解决方案1】:

试试:

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 的解释:

Breakdown:

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

【讨论】:

  • 请解释
猜你喜欢
  • 2016-03-24
  • 2013-02-04
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 2023-03-16
  • 2020-01-26
  • 1970-01-01
  • 2015-10-16
相关资源
最近更新 更多