In VB 2010, you can use the implied properties like C# which turns this
Private _SONo As String
Public Property SONo() As String
Get
Return _SONo
End Get
Set(ByVal value As String)
_SONo = value
End Set
End Property
Into
Public Property SONo() As String
What I want to do is replace the old style with the new style in a few file. Since Visual Studio's find and replace tool allows you to do regular expressions, I assume there must be an expression I can use to do this conversion.
What would the regular expression be to do this conversion?
This could be dangerous as you might have logic in the property setters/getters, but if they don't have logic you could say:
Regular Expression:
Private\s_(\w+)\sAs\s(\w+).*?(^\w+).*?Property.*?End\sProperty
Replace:
${3} Property ${1} As ${2}
I've tested this with RegexBuddy targeting the .NET regex variant. Note, that this may or may not work in the Visual Studio Find/Replace prompt as that is yet another variant.
UPDATE: VS's variant (Dot can't match newlines so we need to add that functionality, also converted: \w = :a, \s = :b, {} for tags, and *? = @):
Private:b_{:a+}:bAs:b{:a+}(.|\n)@{:a+}(.|\n)@Property(.|\n)@End:bProperty
\3 Property \1 As \2
The Regex does the following:
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»