user1946932
user1946932

Reputation: 602

Find and replace function contents in all pages?

Is there a way to find and replace all occurrences of the following in all default.aspx.vb pages in our web site:

Private Function fExampleA() As Boolean

‘Existing code here
‘Existing code here
‘Existing code here etc

End Function

With:

Private Function fExampleA() As Boolean

‘New code here
‘New code here
‘New code here etc

End Function

UPDATE

Yes, the new function is envisaged to be:

Private Function fExampleA() As Boolean
    
    Dim c as new cGeneral
    With c
         .fCommonExampleA()
    End With
    
End Function

Upvotes: 0

Views: 58

Answers (1)

Zhenning Zhang
Zhenning Zhang

Reputation: 312

Find: Private Function (f\w+)\(\) As Boolean(.*\n)*?\s*End Function

Replace: Private Function $1() As Boolean \n\t Dim c as new cGeneral \n\t With c \n \t .$1()\n\t End With \n End Function

This regular expression can achieve the desired result, but it assumes that the code format is consistent with the example you provided. If it's not, you will need to make adjustments, such as finding common points in the function name section. The (.*\n)*?\s*End Function part is used for multi-line searches and doesn't require modification.

During replacement, implicit grouping in the regular expression is used, and $1 is used to call group 1, which is the matched function name.

Upvotes: 1

Related Questions