Format() in Python Regex -
in example below, want {0} , {1} replaced arguments passed format, , {2} should have regex functionality \w{2}
of, "find 2 letter characters". how do this?
q = re.search("{0}\w{2}b{1}\w{2}quarter".format('b', 'a'), search_me).group()
you can put literal {
, }
using {{
, }}
:
>>> "{0}\w{{2}}b{1}\w{{2}}quarter".format('b', 'a') 'b\\w{2}ba\\w{2}quarter'
Comments
Post a Comment