普通的前pression找到字符串中的网址 [英] Regular expression to find URLs within a string
本文介绍了普通的前pression找到字符串中的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:结果
C#code到linkify的URL字符串中的一>
我敢肯定,这是一个愚蠢的问题,但我不能在任何地方找到一个体面的答案。我需要一个良好的URL正前$ P $的C#pssion。它需要找到所有的URL字符串中,这样我可以包装每一个在HTML,使其点击。
I'm sure this is a stupid question but I can't find a decent answer anywhere. I need a good URL regular expression for C#. It needs to find all URLs in a string so that I can wrap each one in html to make it clickable.
-
什么是最好的前pression用于此?
What is the best expression to use for this?
在我有恩pression,什么是他们的正确格式的同行,以取代这些URL的最佳方式?
Once I have the expression, what is the best way to replace these URLs with their properly formatted counterparts?
在此先感谢!
推荐答案
我用这现在:
text = Regex.Replace(text,
@"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)",
"<a target='_blank' href='$1'>$1</a>");
这篇关于普通的前pression找到字符串中的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文