[Solved] Regular expression to match the string [closed]


Here’s one of many ways to get it:

>>> x = r'''"self.unsupported_cmds = [r'\s*clns\s+routing',"'''
>>> print x
"self.unsupported_cmds = [r'\s*clns\s+routing',"
>>> import re
>>> pattern = re.escape(x)
>>> re.match(pattern, x)
<_sre.SRE_Match object at 0x7ffca3f66098>
>>> print pattern
\"self\.unsupported\_cmds\ \=\ \[r\'\\s\*clns\\s\+routing\'\,\"

solved Regular expression to match the string [closed]