从字符串中的第二个括号中提取值

时间:2018-09-28 14:50:01

标签: regex

正在努力为以下内容编写正则表达式的任何人都可以帮忙:

String1 = [The Aggregate Total Incremental Facility Commitments shall not, at any time, exceed [10 million].]

预期输出:String1 = 10 million

String2 = a Borrower (or the Parent) may select an Interest Period of [[ 12] or [24]] Months

预期输出:String2 = [[ 12] or [24]] Months

String3 = excluding all intra-group items and investments in Subsidiaries of any member of the Group) exceeds [10]% of [ABC]

预期输出:String 3 = [10]%

2 个答案:

答案 0 :(得分:0)

这适用于您特定的测试用例,但是不知道为什么/如何获得它们的测试用例,我无法使其适用于其他情况:

.*(\[.*?\]%).*|(?:^[\[]?.*?\[(.*?)\]).*|.*(\[\[.*\]\].\w+)

这不包括 String x = 抱歉。

regexr.com/40b58

答案 1 :(得分:0)

尝试以下

regex1 = (?!.*\[)(.*?)\].*$  // for string1
regex2 = \[[^"]*      // for string2
regex3 = \[.*?\]%     // for string3

demo regex2

demo regex3