rspec/rules/S5996/rule.adoc

20 lines
625 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
In regular expressions the boundaries ``++\^++`` and ``++\A++`` can only match at the beginning of the input (or, in case of ``++\^++`` in combination with the ``++MULTILINE++`` flag, the beginning of the line) and ``++$++``, ``++\Z++`` and ``++\z++`` only at the end.
2021-01-27 13:42:22 +01:00
These patterns can be misused, by accidentally switching ``++\^++`` and ``++$++`` for example, to create a pattern that can never match.
== Noncompliant Code Example
----
// This can never match because $ and ^ have been switched around
2021-01-06 17:38:34 +01:00
Pattern.compile("$[a-z]+^"); // Noncompliant
----
== Compliant Solution
----
2021-01-06 17:38:34 +01:00
Pattern.compile("^[a-z]+$");
----