![](/img/trans.png)
[英]How to focus cursor in between two brackets (parentheses) with Jquery?
[英]How to get the data between last two brackets in Jquery/Javascript
幫助我在最后一個括號之間獲取數據。 下面是兩個示例字符串:
This (is) jquery (Application) and Output: Application
This (is) jquery (Application) with bootstrap (css) and Output: css
我嘗試了下面的代碼
var str = "This (is) jquery (Application)"; pos = str.indexOf("(") + 1;
str = str.slice(pos, str.lastIndexOf(")"));
我得到了第一個(
和最后一個)
之間的值。 如何獲得最后兩個括號之間的值?
為什么不取(
和)
的最后一個索引
pos = str.lastIndexOf("(") + 1; str = str.slice(pos, str.lastIndexOf(")"));
您可以使用 RegEx 獲取匹配字符串並使用最后一個作為結果:
Regex.Matches("(?<=\()(.*?)(?=\))", "This (is) jquery (Application)")
它將返回is
和Application
。 然后你可以把第二個作為結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.