23 lines
567 B
Plaintext
23 lines
567 B
Plaintext
include::description.adoc[]
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,text]
|
|
----
|
|
Pattern.compile("\\1(.)"); // Noncompliant, group 1 is defined after the back reference
|
|
Pattern.compile("(.)\\2"); // Noncompliant, group 2 isn't defined at all
|
|
Pattern.compile("(.)|\\1"); // Noncompliant, group 1 and the back reference are in different branches
|
|
Pattern.compile("(?<x>.)|\\k<x>"); // Noncompliant, group x and the back reference are in different branches
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,text]
|
|
----
|
|
Pattern.compile("(.)\\1");
|
|
Pattern.compile("(?<x>.)\\k<x>");
|
|
----
|
|
|
|
|