Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在下面的示例中,我希望将 {0} 和 {1} 替换为传递给 format 的参数,并且 {2} 应该具有\w{2}“查找两个字母字符”的正则表达式功能。我该怎么做呢?
\w{2}
q = re.search("{0}\w{2}b{1}\w{2}quarter".format('b', 'a'), search_me).group()
你可以把文字{,}使用{{和}}:
{
}
{{
}}
>>> "{0}\w{{2}}b{1}\w{{2}}quarter".format('b', 'a') 'b\\w{2}ba\\w{2}quarter'