regex in java
By traviscj
- 1 minutes read - 63 wordsI can never remember how to do java regexes with Pattern.
Pattern pattern = Pattern.compile("x_(yy|zz)");
String input = "x_yy";
boolean m = pattern.asPredicate().test(input);
System.out.println("matches: " + m);
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
System.out.println("whole matched string: " + matcher.group(0));
System.out.println("matched group: " + matcher.group(1));
}
I also learned a really cool thing IntelliJ can do with pattern matches!
![java regex]({{ site.baseurl }}/assets/java-regex.png)