问题描述
我是 regex 的新手,我有一个问题。是否可以使用正则表达式来识别两个特定字符之间不包含特定单词的块?
我想突出显示以操作、部分、系统部分或字段开头的所有块,后跟任何字符,后跟左括号。然后突出显示是否在下一个右括号之前不包含“ApplicationArea”。
我一直在努力,这就是我可以实现的目标:
(action|part|systempart|field)\((.)*(\s)*(\n)*(\{)[\s]*(?![\s]*(ApplicationArea.*))(([\s\S\r^}]*?)\})
但这仅在 ApplicationArea 是左括号之后的第一个时才突出显示。
field("Max. Dep Bases"; Rec."Max. Dep Bases")
{
ApplicationArea = Basic,Suite;
ToolTip = 'Specifies the value of the Max. Dep Bases field';
}
field("Suggested Value to Adjust"; Rec."Suggested Value to Adjust")
{
ToolTip = 'Specifies the value of the Suggested Value to Adjust field';
}
field("Adjust Depreciation"; Rec."Adjust Depreciation")
{
ToolTip = 'Specifies the value of the Adjust Depreciation field';
ApplicationArea = Basic,Suite;
ToolTip = 'Specifies the value of the Adjust Depreciation field';
}
解决方法
如果外卷曲之间不能有{
和}
:
\b(?:action|(?:system)?part|field)\([^()]*\)\s*\n{(?![^{}]*\bApplicationArea\b[^{}]*})[^{}]*\}
另一个选项可能是匹配字符串开头的开头和结尾的卷曲,并且它们之间的所有链接都不包含 ApplicationArea。
\b(?:action|(?:system)?part|field)\([^()]*\)\s*\n{(?:\n(?!}$|.*\bApplicationArea\b).*)\n}