Created
August 28, 2014 12:11
-
-
Save melkorm/0f4f7d0514c851897ae2 to your computer and use it in GitHub Desktop.
Java RegEx testing class
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
import java.util.regex.Pattern; | |
import java.util.regex.PatternSyntaxException; | |
public class RegexTester { | |
public static void main(String[] arguments) { | |
String userInputPattern = arguments[0]; | |
System.err.println(userInputPattern); | |
String userInputText = arguments[1]; | |
System.err.println(userInputText); | |
try { | |
Pattern p = Pattern.compile(userInputPattern); | |
boolean b = Pattern.matches(userInputPattern, userInputText); | |
System.err.println(b ? "Matches" : "Nope :("); | |
} catch (PatternSyntaxException exception) { | |
System.err.println(exception.getDescription()); | |
System.exit(1); | |
} | |
System.out.println("Syntax is ok."); | |
} | |
} | |
How to run (OSx): | |
javac RegexTester.java | |
java RegexTester "regex" "string to match" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment