Solved

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

Posted on 2013-01-30
7
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 38837579
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
ID: 38840137
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
ID: 38840591
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 38843629
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
ID: 38844430
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
ID: 38844446
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
ID: 38844678
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

726 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