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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -