15 lines
578 B
Plaintext
15 lines
578 B
Plaintext
Theoretically, any string of characters can form a pattern, and therefore a regular expression. However, it is possible to string together a set of characters which do not form a valid regular expression because they use unmatched, and unescaped characters which have special meaning in a regular expression context.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
public boolean matchesPattern(String candidate) {
|
|
String pattern = "a(b"; // this is fine as a plain string
|
|
return candidate.matches("a(b"); // Noncompliant; was "a(b)" or "a\\(b" meant instead?
|
|
}
|
|
----
|
|
|
|
|