0

我是正则表达式的新手,我有一个问题。是否可以使用正则表达式来识别两个特定字符之间不包含特定单词的块?

我想突出显示以 action、part、systempart 或 field 开头的所有块,然后是任何字符,然后是左括号。然后突出显示是否在下一个右括号之前不包含“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';
            }
4

1 回答 1

0

If there can not be { and } between the outer curly's:

\b(?:action|(?:system)?part|field)\([^()]*\)\s*\n{(?![^{}]*\bApplicationArea\b[^{}]*})[^{}]*\}

Regex demo

Another option could be matching the opening and closing curly's at the start of the string, and all linkes in between that do not contains ApplicationArea.

\b(?:action|(?:system)?part|field)\([^()]*\)\s*\n{(?:\n(?!}$|.*\bApplicationArea\b).*)\n}

Regex demo

于 2021-06-02T09:03:19.660 回答