Skip to content

Instantly share code, notes, and snippets.

@BacLuc
Created May 16, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BacLuc/7b9f6598b3dd32883f2b96e5a5084623 to your computer and use it in GitHub Desktop.
Save BacLuc/7b9f6598b3dd32883f2b96e5a5084623 to your computer and use it in GitHub Desktop.
java regex
package com.company;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Regex {
public static void main(String[] args) {
String toMatch = "Looks like you grokked this completely. I think the answer to all your questions is Yes. For details, check out this regular expressions tutorial by Jan Goyvaerts, especially the sections on capturing groups and lookaround assertions. As for your last question, can you be more specific? Perhaps in the form of another question since comments are not really well suited for this? – Tim Pietzcker";
Pattern regex = Pattern.compile(
"\\b([A-Z][a-z]*)\\b"
);
Matcher regexMatcher = regex.matcher(toMatch);
while(regexMatcher.find()){
System.out.println("Found uppercase word: "+regexMatcher.group(1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment