hankknight
asked on
ASP.NET/VB/REGEX: Slashes Break Custom Link Markup
I use this ASP.NET / VB / REGEX code:
It works with this:
But it does not work with this:
The problem is that the slashes mess it up.
input = RegularExpressions.Regex.Replace(input, "\{\[link=([^\]]+)\]\}([^\]]+)\{\[\/link\]\}", "<a href=""$1"">$2</a>")
It works with this:
{[link=xyz]}Link Text{[/link]}
But it does not work with this:
{[link=http://www.example.com?a=1&b=2/]}Link Text{[/link]}
The problem is that the slashes mess it up.
ASKER
With my REGEX,
This:
Becomes this:
This:
{[link=http://www.example.com/]}Link Text{[/link]}
Becomes this:
<a href="<a href="http://www.example.com/">Link">http://www.example.com/">Link</a> Text</a>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That code gives me an error. Is it for VB?
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30201: Expression expected.
ASKER
kaufmed, you are right. Other regex is conflicting with it! Thanks for the tip. I should have posted all my code. Here it is. How can the other rules be modified so they do not conflict? Thanks!
' BB Links
' {[link=url]}text{[/link]}
input = RegularExpressions.Regex.Replace(input, "\{\[link=([^\]]+)\]\}([^\]]+)\{\[\/link\]\}", "<a href=""$1"">$2</a>")
' Links
input = RegularExpressions.Regex.Replace(input, "(https?://\S+[^\s@,.""']+)", "<a href=""$1"">$1</a>")
input = RegularExpressions.Regex.Replace(input, "(?<!\S)(\www\.\S+[^\s@,.""']+)", "<a href=""http://$1"">$1</a>")
' Email Addresses
input = RegularExpressions.Regex.Replace(input, "\w[\w\.]*\w?@[\w\.]+\w", "<a href=""mailto:$0"">$0</a>")
ASKER
I realize that is a separate question so I asked it here.
https://www.experts-exchange.com/questions/28017172/ASP-NET-VB-REGEX-First-expression-messed-up-by-additional-expressions.html
https://www.experts-exchange.com/questions/28017172/ASP-NET-VB-REGEX-First-expression-messed-up-by-additional-expressions.html
What would be the resultant output you are expecting and what is it that you are getting?