Can anybody explain this piece of code
What does
^%s
mean? why is it used there?the second
'%'
. what does it mean and why is it used therewhat does
string.printable
mean?re.compile('[^%s]' % re.escape(string.printable))
Can anybody explain this piece of code
What does ^%s
mean? why is it used there?
the second '%'
. what does it mean and why is it used there
what does string.printable
mean?
re.compile('[^%s]' % re.escape(string.printable))
Half of this question is a matter of regex syntax, and the other half is python's string format syntax.
^
character when inside of []
brackets indicates negation. i.e. the opposite of what's matched in the brackets. See a more complete answer on that expressionre.compile
ing. The %s
indicates the str()
representation of the "argument" to the format string, which is the term after the %
character - i.e. re.escape(string.printable)
Read the docs for more examples of format specifiersstring.printable
is a built-in method specifying "printable" ASCII characters - see the docIn short, it looks like that line is compiling a regex pattern that matches anything except the printable ASCII characters in a string