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