私の文字列:
download_recording true Package available http://abc.com/recDownload/635131586215948750.exe
上記の文字列から取得する方法はhttp://abc.com/recDownload/635131586215948750.exe
?
助けてください
このブログにはサンプル コードが含まれています。
http://blog.houen.net/java-get-url-from-string/
この質問と同様に:
そして、これも役立つかもしれません:
これは、プレフィックス付きのプロトコルを含むものと一致させるための非常に単純なものです。
[a-z]+:\/\/[^ \n]*
Pattern.compile("[a-z]+:\/\/[^ \n]*").matcher(
"download_recording true Package available http://abc.com/recDownload/635131586215948750.exe click the link"
).find();
//"http://abc.com/recDownload/635131586215948750.exe"
同等の JavaScript
'download_recording true Package available http://abc.com/recDownload/635131586215948750.exe click the link'
.match(/[a-z]+:\/\/[^ \n]*/)
string クラスの split メソッドを単純に使用すると、これが解析されます。
String s = "download_recording true Package available http://abc.com/recDownload/635131586215948750.exe";
//We now have the values on either side of where http:// was
String[] splitted = s.split("http://");
//so index 1 is the url and we can just append http:// back on the beginning to get the whole url
String url = "http://" + splitted[1];
この正規表現はあなたが探しているものだと思います:
(http\:\/\/){0,1}(www){0,1}[\.]{0,1}[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\/{1}[a-zA-Z0-9_\.]+)*