2

私の文字列:

download_recording true Package available http://abc.com/recDownload/635131586215948750.exe

上記の文字列から取得する方法はhttp://abc.com/recDownload/635131586215948750.exe?

助けてください

4

4 に答える 4

3

このブログにはサンプル コードが含まれています。

http://blog.houen.net/java-get-url-from-string/

この質問と同様に:

文字列からURLを検出して抽出しますか?

そして、これも役立つかもしれません:

文字列内の URL の存在を検出する方法

于 2013-08-27T07:34:40.503 に答える
1

これは、プレフィックス付きのプロトコルを含むものと一致させるための非常に単純なものです。 [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]*/)
于 2013-08-27T07:36:38.590 に答える
0

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];
于 2013-08-27T07:33:49.757 に答える
0

この正規表現はあなたが探しているものだと思います:

(http\:\/\/){0,1}(www){0,1}[\.]{0,1}[a-zA-Z0-9_]+\.[a-zA-Z0-9_]+(\/{1}[a-zA-Z0-9_\.]+)*

于 2013-08-27T07:37:24.373 に答える