Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
The code here uses a regular expression that is invalid according to the syntax for regular expressions. This statement will throw a PatternSyntaxException when executed. – 2013-10-14
Syntax errors also called as parsing errors, are caught by ParseSyntaxException in Java whenever incorrect syntax is passed in any regular expression.
<code Java> public class PatternExample {
public static void main(String[] args) { Pattern pattern = Pattern.compile('.xx.'); Matcher matcher = pattern.matcher('MxxY'); System.out.println('Input String matches regex - '+matcher.matches()); // bad regular expression pattern = Pattern.compile('*xx*'); }
} </Code>
<code Java> String str = 'bbb'; System.out.println('Using String matches method: '+str.matches('.bb')); System.out.println('Using Pattern matches method: '+Pattern.matches('.bb', str)); </Code>
Benchmark project | Precision | Recall | ||||
---|---|---|---|---|---|---|
FB | JT | Delta | FB | JT | Delta | |
Project … | …% | …% | …% | …% | …% | …% |
Project … | …% | …% | …% | …% | …% | …% |
FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs