0

「リンクのコピー」みたいなものを作りたいのですが、

たとえば、次のファイルにリストされています。

this is example http://stackoverflow.com and nothing more.
and another way http://www.google.com.

URLのみを保持する方法は? お気に入り:

 http://stackoverflow.com
 http://www.google.com

私はこのようなことを知っています:

MatchCollection mc = Regex.Matches(str, "http.+?com", RegexOptions.Singleline);

それは良いコードですか?結果^をテキストファイルにコピーするにはどうすればよいですか?

その例を教えてください。

ありがとう。

4

1 に答える 1

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\-._~%!$&'()*+,;=:@/?]*)?
于 2012-06-21T20:53:53.900 に答える