The S6353 rule for Python claims that
[0-9] is equivalent to
\d in the regex engine, which is not precisely true and could cause issues if applied as a blanket statement.
\d is actually unicode/locale-aware and thus not the same as
For an example where this could bite you, consider the following:
>>> import re >>> re.findall('[0-9]+', '123 ٦٩ 456') ['123', '456'] >>> re.findall('\d+', '123 ٦٩ 456') ['123', '٦٩', '456']
As you can see, the results are different. In fact, I would generally argue against using
\d and in favor of using
[0-9] in most cases in Python for this reason (even though it’s slightly more verbose). Typically, you’d only want to match the actual digits 0-9, and not also the Arabic numerals ٦٩ as in this example.