★★ Java の宿題ここで答えます Part 68 ★★at TECH
★★ Java の宿題ここで答えます Part 68 ★★ - 暇つぶし2ch55:Indooroopilly
09/07/27 22:15:31
import java.util.Scanner;
import java.util.regex.*;
public class KeywordExtractor{

public static void main(String [] args)throws Exception{

String keyword = "q=([^&]+)";
Pattern pattern = Pattern.compile(keyword);

System.out.print("Input URL: ");
Scanner scan = new Scanner(System.in);
Matcher matcher;
String line = "";
while(scan.hasNext()){
line = scan.nextLine();
matcher = pattern.matcher(line);
if(matcher.find()){
String foundWord = matcher.group().replaceAll("q=", "");
System.out.println("Keyword: " + foundWord);
}else{
System.out.println("Did not find any keyword in the text.");
}
matcher.reset();
System.out.print("Try other URL: ");
}
}
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch