Created
June 1, 2018 07:13
-
-
Save AllanJunLi/5b8ac395b667d1a37a38404738e68436 to your computer and use it in GitHub Desktop.
Learning Java regular expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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