Solved

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

Posted on 2013-01-30
7
292 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
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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…

786 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