在这个问题中,提供了一个用于捕获分隔符之间的字符串的正则表达式:
测试: This is a test string [more or less]
正则表达式: (?<=\[)(.*?)(?=\])
回报: more or less
如果要捕获的字符串也包含分隔符怎么办?
测试1: This is a test string [more [or] less]
返回1: more [or] less
测试 2: This is a test string [more [or [and] or] less]
返回2: more [or [and] or] less
和多个括号?
测试 3: This is a test string [more [or [and] or] less] and [less [or [and] or] more]
返回 3: more [or [and] or] less
,less [or [and] or] more
哪个正则表达式会这样做?或者哪个小的 ruby/python 脚本可以做到这一点?