regex - Replace custom tags with <a href> tags -


in asp.net application have plain text field. want allow user able enter url's in following format:

[url="http://www.google.com"]google[/url] 

these saved database directly entered. on retrieveal however, i'd convert above following html format make active on-screen:

<a href="http://www.google.com">google</a> 

the reason approach avoid tampering built-in asp.net validation routines, trigger error when sees <a in form input string.

i've seen other examples on stackoverflow regex used parse string, however, cannot find can follow multiple occurrences of [url...] may exist in single string.

can please offer me example of how parse such string, say...

try funky new search engine: [url="http://www.google.com"]google[/url] or older 1 in day: [url="http://uk.altavista.com"]altavista[/url]

...to convert each occurrence desired format? regex isn't strong-point sadly.

thanks.

following hamza dzcyberdev's comments used regex pattern within regexhero , found regexhero generated asp.net. therefore simple code below achieves outcome needed:

dim s string = txt_input.text.trim dim strregex string = "\[url\s?=\s?""?(.*?)""?\](.*?)\[\/url\]" dim myregex new regex(strregex) dim strreplace string = "<a href=""$1"">$2</a>" ltl_output.text = myregex.replace(s, strreplace) 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -