Python 2.6+ str.format() and regular expressions

后端 未结 2 1509
醉梦人生
醉梦人生 2021-01-07 17:59

Using str.format() is the new standard for formatting strings in Python 2.6, and Python 3. I\'ve run into an issue when using str.format() with reg

2条回答
  •  臣服心动
    2021-01-07 18:26

    Per the documentation, if you need a literal { or } to survive the formatting opertation, use {{ and }} in the original string.

    '^(w{{3}}\.)?([0-9A-Za-z-]+\.){{1}}{domainName}$'.format(domainName = 'delivery.com')
    

提交回复
热议问题