将外部链接重定向到 C# 中的中间页面
Redirecting external links to an intermediate page in c#
我正在使用以下代码来识别来源 html 并为中间页面附加 url。
sourceHtml = Regex.Replace(sourceHtml,
@"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)","http://domain.com/out/?url=");
虽然这段代码运行完美,但我遇到了两个问题,
1.It用中间页面link.
替换'a'标签的内容(与href值相同)
2.It 也为 'img' 标签附加 url。
请帮助我将此正则表达式仅应用于 href 值。
尝试用这个替换你的正则表达式:
href\=\""((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)\""
它只会替换 href 值。
我正在使用以下代码来识别来源 html 并为中间页面附加 url。
sourceHtml = Regex.Replace(sourceHtml,
@"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)","http://domain.com/out/?url=");
虽然这段代码运行完美,但我遇到了两个问题,
1.It用中间页面link.
替换'a'标签的内容(与href值相同)2.It 也为 'img' 标签附加 url。
请帮助我将此正则表达式仅应用于 href 值。
尝试用这个替换你的正则表达式:
href\=\""((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)\""
它只会替换 href 值。