Skip to content

Instantly share code, notes, and snippets.

@AllanJunLi
Created June 1, 2018 07:13
Show Gist options
  • Save AllanJunLi/5b8ac395b667d1a37a38404738e68436 to your computer and use it in GitHub Desktop.
Save AllanJunLi/5b8ac395b667d1a37a38404738e68436 to your computer and use it in GitHub Desktop.
Learning Java regular expression
public class RegexTestStrings {
public static final String TEST = "This is my small example string which I'm going to use for pattern matching.";
public static void main(String[] args) {
System.out.println(TEST.matches("\\w.*"));
// split by whitespace
String[] splitStr = TEST.split("\\s+");
System.out.println(splitStr.length);
for (String str : splitStr) {
System.out.println(str);
}
// replace all whitespace with tabs
System.out.println(TEST.replaceAll("\\s+", "\t"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment