2021-07-20 17:49:33 +02:00
include::../description.adoc[]
2021-04-28 16:49:39 +02:00
2021-11-03 17:45:14 +01:00
To match a literal string instead of a regular expression, either all special characters should be escaped, the `Pattern.LITERAL` flag or methods that don't use regular expressions should be used.
2021-04-28 16:49:39 +02:00
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
Pattern.compile("([");
str.matches("([");
str.replaceAll("([", "{");
str.matches("(\\w+-(\\d+)");
----
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
Pattern.compile("\\(\\[");
Pattern.compile("([", Pattern.LITERAL);
str.equals("([");
str.replace("([", "{");
str.matches("(\\w+)-(\\d+)");
----
2021-04-28 18:08:03 +02:00
2023-03-22 15:25:58 +01:00
include::../rspecator.adoc[]