【发布时间】:2017-08-24 06:47:22
【问题描述】:
已在此处检查:C# Remove URL from String 和 here 和此处Remove URLs from text string。
我尝试了上一篇文章中的正则表达式:Regex.Replace(txt, "!\b(((ht|f)tp(s?))\://)?(www.|[a-z].)[a-z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-z0-9\.\,\;\?\\'\\\\\+&%\$#\=~_\-]+))*\b!i", "")
我还尝试了引用的正则表达式:^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$
但两者都不会删除网址。
我想使用 VB 从字符串中删除所有 URL。这些 URL 不在 a 标记中。
示例字符串:This is https://www.example.com/an-example-url and http://www.example.com/and-some-friendlyurl?utm_campaign=test&id=4.<br/>.Themes.
想要的结果:This is and .<br/>.Themes.
【问题讨论】:
-
(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+[\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#]这个正则表达式有效,检查here...您可以将它与replace结合使用并删除匹配项...
标签: asp.net regex string vb.net url