我想制作类似“复制链接”的内容,
例如:
中列出的文件this is example http://stackoverflow.com and nothing more.
and another way http://www.google.com.
如何只保留网址?像:
http://stackoverflow.com
http://www.google.com
我知道这样的事情:
MatchCollection mc = Regex.Matches(str, "http.+?com", RegexOptions.Singleline);
这是一个很好的代码?如何将结果^复制到文本文件?
请举例说明。
感谢。
答案 0 :(得分:3)
我会更加明显
Protocol, domain name, page and CGI parameters are captured into backreferenes 1 through 4
\b((?#protocol)https?|ftp)://((?#domain)[-A-Z0-9.]+)((?#file)/[-A-Z0-9+&@#/%=~_|!:,.;]*)?((?#parameters)\?[A-Z0-9+&@#/%=~_|!:,.;]*)?
甚至
URL: RFC 3986
Validate if a string holds a URL as specified in RFC 3986. Both absolute and relative URLs are supported.
(# Scheme
[a-z][a-z0-9+\-.]*:
(# Authority & path
//
([a-z0-9\-._~%!$&'()*+,;=]+@)? # User
([a-z0-9\-._~%]+ # Named host
|\[[a-f0-9:.]+\] # IPv6 host
|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\]) # IPvFuture host
(:[0-9]+)? # Port
(/[a-z0-9\-._~%!$&'()*+,;=:@]+)*/? # Path
|# Path without authority
(/?[a-z0-9\-._~%!$&'()*+,;=:@]+(/[a-z0-9\-._~%!$&'()*+,;=:@]+)*/?)?
)
|# Relative URL (no scheme or authority)
([a-z0-9\-._~%!$&'()*+,;=@]+(/[a-z0-9\-._~%!$&'()*+,;=:@]+)*/? # Relative path
|(/[a-z0-9\-._~%!$&'()*+,;=:@]+)+/?) # Absolute path
)
# Query
(\?[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?
# Fragment
(\#[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?