问题
How can I search for, say, a sequence of 10 isprint
characters in a given string in Python?
With GNU grep, I would simply do grep [[:print:]]{10}
回答1:
Since POSIX is not supported by Python re
module, you have to emulate it with the help of character class.
You can use the one from the regular-expressions.info and add a limiting quantifier {10}
:
[\x20-\x7E]{10}
See demo
Alternatively, you can use Matthew Barnett regex module that claims to support POSIX character classes (POSIX character classes are supported.).
来源:https://stackoverflow.com/questions/31915346/python-posix-character-class-in-regex