Regular Expressions
Post # 240 permalink Topic #238 by mreschke on 2011-03-08 10:53:32 (viewed 452 times)

VB.NET Regex Replace Between Strings[-][- -][++]

I have a large html file, I want to remove anything between the <trimweb> tags, even if the contents is on multiple lines. There is a regex option called RegexOptions.MultiLine which I though would work, but its actually the RegexOptions.Singleline below what makes it span multiple lines, see http://msdn.microsoft.com/en-us/library/ms972966.aspx for details on RegexOptions.Singleline.

VB Code Snippet
Dim reg As New Regex("<trimweb>.*?</trimweb>", RegexOptions.Singleline Or RegexOptions.IgnoreCase)
lblSurvey.Text = reg.Replace(lblSurvey.Text, "")
 

VB.NET Misc Replace[-][- -][++]

VB Code Snippet
Dim search As String = Nothing
Dim replace As String = Nothing
For Each drTD As DataRow In dsTemplateDetail.Tables(0).Rows
    search = "{{" & drTD.Item("TemplateObjectType").ToString & "ID:" & drTD.Item("TemplateObjectID").ToString & "}}"
    If drTD.Item("TemplateObjectType").ToString.ToLower = "image" Then
        replace = "<img src='http://www" & serverNum & ".example.com/" & drTD.Item("TemplateObjectData").ToString & "' border='0' />"
    Else
        replace = drTD.Item("TemplateObjectData").ToString
    End If
    templateHtml = templateHtml.Replace(search, replace)
Next
 
'Search/Replace Client-Side Scripts
search = "name='_rad" : replace = "onclick='click_answer()' name='_rad" : templateHtml = templateHtml.Replace(search, replace)
search = "name=""_rad" : replace = "onclick='click_answer()' name=""_rad" : templateHtml = templateHtml.Replace(search, replace)
search = "name='_chk" : replace = "onclick='click_answer()' name='_chk" : templateHtml = templateHtml.Replace(search, replace)
search = "name=""_chk" : replace = "onclick='click_answer()' name=""_chk" : templateHtml = templateHtml.Replace(search, replace)
 
'Remove any <!--<emailonly>-->...<!--</emailonly>--> tags
Dim reg As New Regex("<!--<emailonly>-->.*?<!--</emailonly>-->", RegexOptions.Singleline Or RegexOptions.IgnoreCase)
templateHtml = reg.Replace(templateHtml, "")