- 55 名前:Indooroopilly mailto:sage [2009/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: "); } } }
|

|