hankknight
asked on
ASP.NET/VB/REGEX: Format special content in columns
Using ASP.NET/VB and Regualar Expressions, how can I change this:
Hello World
===Row 1 Column 1
===Row 1 Column 2
===Row 1 Column 3
===Row 2 Column 1
===Row 2 Column 2
===Row 2 Column 3
Hello Again World
to this:
Hello World
<span class="infoColumns">
<span class="col1">Row 1 Column 1</span>
<span class="col2">Row 1 Column 2</span>
<span class="col3">Row 1 Column 3</span>
</span>
<span class="infoColumns">
<span class="col1">Row 2 Column 1</span>
<span class="col2">Row 2 Column 2</span>
<span class="col3">Row 2 Column 3</span>
</span>
Hello Again World
ASKER
I want this to be done using REGEX and I need to to work with VB, not C#.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get an error:
Compiler Error Message: BC30516: Overload resolution failed because no accessible 'Replace' accepts this number of arguments.
Dim result As String = Regex.Replace(source, pattern, replacement)
ASKER
Thanks, Could you please make it work with this code?
<%@ Page Language="VB" %>
<%
Dim input As String = "{-} {c} {tm} {r}" & VbNewLine & "Hello World" & VbNewLine & VbNewLine & "===Row 1 Column 1" & VbNewLine & "===Row 1 Column 2" & VbNewLine & "===Row 1 Column 3" & VbNewLine & "===Row 2 Column 1" & VbNewLine & "===Row 2 Column 2" & VbNewLine & VbNewLine & "Hello World"
input = Server.HtmlEncode(input)
' Links
input = RegularExpressions.Regex.Replace(input, "(?<!\S)(https?://\S+[^\s@,.""']+)", "<a target=""_blank"" href=""$1"">$1</a>")
input = RegularExpressions.Regex.Replace(input, "(?<!\S)(\www\.\S+[^\s@,.""']+)", "<a target=""_blank"" href=""http://$1"">$1</a>")
' Email Addresses
input = RegularExpressions.Regex.Replace(input, "(?<!\S)\w[\w\.]*\w?@[\w\.]+\w", "<a href=""mailto:$0"">$0</a>")
' Spaces
input = RegularExpressions.Regex.Replace(input, " ", " ")
' Line Breaks
input = RegularExpressions.Regex.Replace(input, VbNewLine, VbNewLine +"<br />")
' Dash Symbol
input = RegularExpressions.Regex.Replace(input,"-- ", "— ")
' Bullet Symbol
input = RegularExpressions.Regex.Replace(input, "\{\-\}", "•")
' Copyright Symbol
input = RegularExpressions.Regex.Replace(input, "\{[cC]\}", "©")
' Trademark Symbol
input = RegularExpressions.Regex.Replace(input, "\{[tT][mM]\}", "™")
' Registered Trademark Symbol
input = RegularExpressions.Regex.Replace(input, "\{[rR]\}", "®")
' Fix Double Entities
input = RegularExpressions.Regex.Replace(input, "(?<=&)amp;(?=#?\w+;)", String.Empty)
Response.write(input)
%>
Given the input in the question the following code snippet should give you what you are looking for.
Open in new window