rspec/rules/S6035/java/rule.adoc

19 lines
452 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
When an alternation contains multiple alternatives that consist of a single character, it can be rewritten as a character class. This should be preferred because it is more efficient and can even help prevent stack overflows when used inside a repetition (see rule S5998 ).
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
Pattern.compile("a|b|c"); // Noncompliant
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
Pattern.compile("[abc]");
// or
Pattern.compile("[a-c]");
----