如何在Python中给定的字符串中搜索10个isprint字符的序列?
How can I search for, say, a sequence of 10 isprint characters in a given string in Python?
使用GNU grep,我只需执行grep [[:print:]]{10}
With GNU grep, I would simply do grep [[:print:]]{10}
推荐答案由于Python re模块不支持POSIX,因此必须在字符类的帮助下对其进行仿真.
Since POSIX is not supported by Python re module, you have to emulate it with the help of character class.
您可以使用 regular-expressions.info 中的一个并添加限制量词{10}:
You can use the one from the regular-expressions.info and add a limiting quantifier {10}:
[\x20-\x7E]{10}请参见演示
或者,您可以使用 Matthew Barnett regex模块,该模块声称支持POSIX字符类(支持POSIX字符类.).
Alternatively, you can use Matthew Barnett regex module that claims to support POSIX character classes (POSIX character classes are supported.).
更多推荐
Python:正则表达式中的POSIX字符类?
发布评论