Saturday, 14 September 2013

Java vs. Python Regular Expression?

Java vs. Python Regular Expression?

I am searching through a string for a particular regex.
In python, my code is:
regexChecker = re.match("regularExpression", stringToSearch)
if regexChecker == true:
...
Is there an equivalent in Java? Or is something like this the only way?
boolean isRegex;
try {
Pattern.compile(input);
isRegex = true;
...
} catch (PatternSyntaxException e) {
isRegex = false;
...
}

No comments:

Post a Comment