Solved

ASP.NET/VB/REGEX: Slashes Break Custom Link Markup

Posted on 2013-01-30
7
268 Views
Last Modified: 2013-02-01
I use this ASP.NET / VB / REGEX code:

input = RegularExpressions.Regex.Replace(input, "\{\[link=([^\]]+)\]\}([^\]]+)\{\[\/link\]\}", "<a href=""$1"">$2</a>")

Open in new window


It works with this:
{[link=xyz]}Link Text{[/link]}

Open in new window


But it does not work with this:
{[link=http://www.example.com?a=1&b=2/]}Link Text{[/link]}

Open in new window


The problem is that the slashes mess it up.
0
Comment
Question by:hankknight
  • 4
  • 2
7 Comments
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
Can you tell a bit on what you mean by 'does not work' and 'mess it up'?
What would be the resultant output you are expecting and what is it that you are getting?
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
With my REGEX,

This:
{[link=http://www.example.com/]}Link Text{[/link]}

Open in new window


Becomes this:
<a href="<a href="http://www.example.com/">Link">http://www.example.com/">Link</a> Text</a>

Open in new window

0
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 250 total points
Comment Utility
I tried this:

string input ="{[link=xyz]}Link Text{[/link]}";
input = Regex.Replace(input, @"\{\[link=([^\]]+)\]\}([^\]]+)\{\[\/link\]\}", @"<a href=""$1"">$2</a>");
Response.Write(input + "<br/>");

string input2 = "{[link=http://www.example.com?a=1&b=2/]}Link Text{[/link]}";
input2 = Regex.Replace(input2, @"\{\[link=([^\]]+)\]\}([^\]]+)\{\[\/link\]\}", @"<a href=""$1"">$2</a>");

Open in new window


I got this output:
<a href="xyz">Link Text</a><br/>
<a href="http://www.example.com?a=1&b=2/">Link Text</a>

Open in new window

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
I'm not sure I understand the issue either. The logic appears to work fine for me as well:

Screenshot
Are you certain there isn't some other code influencing the output you are receiving?
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
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.

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
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>")

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
I realize that is a separate question so I asked it here.
http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_28017172.html
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now