这可能会很危险,因为你可能在属性的setter/getter中有逻辑,但如果它们没有逻辑,你可以这样说:
正则表达式:
Private\s_(\w+)\sAs\s(\w+).*?(^\w+).*?Property.*?End\sProperty
替换:
${3} Property ${1} As ${2}
我已经使用RegexBuddy测试过,目标是.NET正则表达式变体。请注意,这可能在Visual Studio查找/替换提示中工作或不工作,因为那是另一种变体。
更新:VS的变体(点不能匹配换行符,因此我们需要添加该功能,还将\w = :a,\s = :b,{}用于标记,*?= @):
Private:b_{:a+}:bAs:b{:a+}(.|\n)@{:a+}(.|\n)@Property(.|\n)@End:bProperty
\3 Property \1 As \2
正则表达式的作用如下:
Options: dot matches newline; case insensitive; ^ and $ match at line breaks
Match the characters “Private” literally «Private»
Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s»
Match the character “_” literally «_»
Match the regular expression below and capture its match into backreference number 1 «(\w+)»
Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s»
Match the characters “As” literally «As»
Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s»
Match the regular expression below and capture its match into backreference number 2 «(\w+)»
Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the regular expression below and capture its match into backreference number 3 «(\w+)»
Match a single character that is a “word character” (letters, digits, and underscores) «\w+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the characters “Property” literally «Property»
Match any single character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the characters “End” literally «End»
Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s»
Match the characters “Property” literally «Property»