rspec/rules/S6397/php/rule.adoc

35 lines
966 B
Plaintext
Raw Normal View History

Character classes in regular expressions are a convenient way to match one of several possible characters by listing the allowed characters or ranges of characters. If a character class contains only one character, the effect is the same as just writing the character without a character class.
Thus, having only one character in a character class is usually a simple oversight that remained after removing other characters of the class.
== Noncompliant Code Example
----
/a[b]c/
----
== Compliant Solution
----
/abc/
----
== Exceptions
This rule does not raise when the character inside the class is a metacharacter. This notation is sometimes used to avoid escaping (e.g., ``++[.]{3}++`` to match three dots).
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace this character class by the character itself.
=== Highlighting
The character class.
endif::env-github,rspecator-view[]