我有一个字符串为"测试我找到这个[测试$ 12345]并且没有找到[测试$ SS7890]这个"。我必须找到12345而不是7890.
答案 0 :(得分:0)
这个正则表达式将:
[test$
和]
正则表达式:
(?<=\[test\$)([0-9]+(?=]))
直播示例
https://regex101.com/r/bY1kH8/3
(?<=\[test\$) Positive Lookbehind - Assert that the regex below can be matched
\[ matches the character [ literally
test matches the characters test literally (case sensitive)
\$ matches the character $ literally
1st Capturing group ([0-9]+(?=]))
[0-9]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
0-9 a single character in the range between 0 and 9
(?=]) Positive Lookahead - Assert that the regex below can be matched
] matches the character ] literally