Java正则类

之前一直研究正则的内容,一直忽略java的类,最近由于需要经常用到,把代码记录下来:

 

String line = “This order was placed( iOS 10.3.1;) for QT3000! OK?”;
String pattern = “iOS ([^;]*);”;

Pattern r = Pattern.compile(pattern);

Matcher m = r.matcher(line);
if (m.find()) {
System.out.println(“Found value: ” + m.group(0));
System.out.println(“Found value: ” + m.group(1));
} else {
System.out.println(“NO MATCH”);
}

发表评论

您的电子邮箱地址不会被公开。