我正在尝试创建一个正则表达式来匹配外括号,但忽略了外括号内注释行的括号。
示例字符串:
(
this is an example;
// this is a comment line with an '(' in it and should be ignored
this is (another) line;
)
我当前的正则表达式:
\(((?>\((?<c>)|[^()]+|\)(?<-c>))*(?(c)(?!)))\)
这就是我得到的:
(' in it and should be ignored
this is (another) line;
)
但我需要这个:
this is an example;
// this is a commentline with an '(' in it and should be ignored
this is (another) line;
答案 0 :(得分:1)
以下是执行此操作的方法。
注意:使用DOTOALL
标记s
允许.
匹配换行符。
Fixed your demo使用lazy
量词?
。
上述正则表达式在许多情况下都有效。经过OP的许多其他规范之后是最终的演示。
的 Final Demo 强>
答案 1 :(得分:0)
试试这个
"controlOwners": [{
"worker": {
"workerKey": -1093,
"sourceFeed": null,
"statusLookUpCode": null,
"externalId": null,
"createdUserText": null,
"createdTimestamp": null,
"modifiedUserText": null,
"modifiedTimestamp": null,
"stdId": "ZK84T1N",
"ccId": null,
"empClasId": null,
"deptId": null,
"fullName": "Rajasekaran, Shanmuga",
}
}],