1. 程式人生 > >查詢字串中指定字元

查詢字串中指定字元

1.查詢字串中指定字元

String qqBrowser = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0; QQBrowser/7.7.28658.400) like Gecko";//字串

String regStr = "QQBrowser";//查詢指定字元
Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(qqBrowser);

boolean result = matcher.find();

if(result){

System.out.println("找到QQBrowser字元");

}else{

System.out.println("未找到QQBrowser字元");

}