In my ASP.NET application I have a plain text field. I want to allow the user to be able to enter URL's in the following format:用<a href> tags
[url="http://www.google.com"]Google[/url]
These would be saved to a database directly as they were entered. On retrieveal however, I'd like to convert the above into the following HTML format to make it active on-screen:
<a href="http://www.google.com">Google</a>
The reason for this approach is to avoid tampering with the built-in ASP.NET validation routines, which trigger an error when it sees <a
in a form input string.
I've seen other examples on StackOverflow where RegEx is used to parse the string, however, I cannot find anything that I can follow where multiple occurrences of [url...]
may exist in a single string.
Can anyone please offer me an example of how to parse such a string, say...
Try this funky new search engine: [url="http://www.google.com"]Google[/url] Or this older one from back in the day: [url="http://uk.altavista.com"]AltaVista[/url]
...to convert each occurrence into the desired format? RegEx isn't my strong-point sadly.
Thanks.
几乎类似的问题,我回答[在正则表达式聊天室](http://chat.stackoverflow.com/transcript/message/9370083#9370083),但在PHP中。如果在ASP中有类似的功能,你可以用'url'和输出替换'size' ......另外我认为有一个错字'Google' I think you meant 'Google'。 – HamZa 2013-05-13 09:44:25
嗨。谢谢是的,有一个错字纠正。至于RegEx,在VB.NET中它不会返回匹配。不知道是否双引号会干扰(这是VB.NET中的字符串符号),因此如果有意义的话,您可以使用双双引号在字符串中返回单个双引号? 'Dim r As New Regex(“/ \ [url \ s?= \ s?”“?(。*?)”“?\](。*?)\ [\/url \]/s”)' – EvilDr 2013-05-13 10:06:21
我不熟悉VB.net或ASP,这里是[在线测试人员](http://i.stack.imgur.com/L2eL5.jpg)的屏幕截图,你可以加入我们的[正则表达式室]( http://chat.stackoverflow.com/rooms/25767/regex)。 – HamZa 2013-05-13 10:31:28