「Java/正規表現」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==ヒットする文字列をすべて取得== Pattern pattern = Pattern.compile("(http://example.com/img/[0-9a-z-]+/mobile/[0-9]+_128x128.jpg)"); Matcher matcher = pat...」) |
(→ヒットする文字列をすべて取得) |
||
| (同じ利用者による、間の3版が非表示) | |||
| 行5: | 行5: | ||
while (matcher.find()) { | while (matcher.find()) { | ||
Log.d("tag1", "url=" + matcher.group(1)); | Log.d("tag1", "url=" + matcher.group(1)); | ||
| + | } | ||
| + | |||
| + | ==後方一致== | ||
| + | Pattern pattern = Pattern.compile(".mp4$"); | ||
| + | Matcher matcher = pattern.matcher(url); | ||
| + | while (matcher.find()) { | ||
| + | Log.d("tag1", "url=" + url); | ||
} | } | ||
2019年3月19日 (火) 15:17時点における最新版
ヒットする文字列をすべて取得
Pattern pattern = Pattern.compile("(http://example.com/img/[0-9a-z-]+/mobile/[0-9]+_128x128.jpg)");
Matcher matcher = pattern.matcher(html);
// 検索ヒット
while (matcher.find()) {
Log.d("tag1", "url=" + matcher.group(1));
}
後方一致
Pattern pattern = Pattern.compile(".mp4$");
Matcher matcher = pattern.matcher(url);
while (matcher.find()) {
Log.d("tag1", "url=" + url);
}
