import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = ".*斗地主";
final String string = "听好听的歌\n\n"
+ "我想听蜻蜓fm郭德纲的相声\n"
+ "我要听蜻蜓fm郭德纲的相声等等等等\n"
+ "蜻蜓的是的是的\n"
+ "听周杰伦的歌\n"
+ "蜻蜓fm于谦的相声\n"
+ "蜻蜓fm的于谦的相声\n"
+ "想听skds的草根创业最好的项目\n"
+ "想听刘德华的歌\n"
+ "我想听于放的相声的地点的电视\n"
+ "想听好听的音乐\n"
+ "想听铁齿铜牙纪晓岚\n"
+ "我想听中国之声\n"
+ "要听圣诞节\n\n"
+ "听蜻蜓fm\n\n"
+ "我想听相声\n"
+ "好听的歌\n"
+ "听广播电台\n"
+ "周杰伦的菊花台\n"
+ "听fm\n"
+ "听六千的相\n"
+ "听加快时间打开手机端\n"
+ "听有声书\n"
+ "听音乐\n"
+ "听蜻蜓fm收银员\n"
+ "听歌曲\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html