Python: POSIX character class in regex?

How can I find, for example, a sequence of 10 isprint

characters in a given string in Python?

With GNU grep, I would just do grep [[:print:]]{10}

+3


source to share


1 answer


Since POSIX is not supported by the Python module re

, you must emulate it using a character class.

You can use one of the regular-expressions.info and add a limit quantifier {10}

:

[\x20-\x7E]{10}

      



Watch the demo

Alternatively, you can use Matthew Barnett's regex module , which claims to support POSIX character classes (POSIX character classes are supported).

+4


source







All Articles