我有这样的文本:
const {
b {
description "Create B1"
uri "ms:///a/v1/create-b"
}
c {
description "Create C1"
uri "ms:///a/v1/create-c"
}
d {
description "Create D1"
uri "ms:///a/v1/create-d"
}
}
const {
b {
description "Create B2"
uri "ms:///a/v1/create-b"
}
c {
description "Create C2"
uri "ms:///a/v1/create-c"
}
d {
description "Create D2"
uri "ms:///a/v1/create-d"
}
}
我正在尝试获取
const
之间的所有内容,目前我想到的正则表达式是:const {(?s)(.*)}.*?(?=const)
。这只能给出第一个出现的匹配项,我无法找出如何获取其他全部匹配项(在原始文件中有更多const
对象)。如果你有任何指导,请提供帮助。
你可以在此链接中测试这个正则表达式:https://regex101.com/r/I4W5cR/1。
re.findall
或者PHP的preg_match_all()
,它应该会返回所有出现的结果。 - Barmar