0

I want to do something like:

re.match(r'\d{3} {}'.format('test'), '123 test')

However it doesn't work.

I'm only able to do regular string as patter and to escape many re characters, like:

re.match('\\d{{3}} {}'.format('test'), '123 test')

Is there a way I can keep using r'' pattern but also do formatting string?

jtcloud
  • 521
  • 1
  • 4
  • 18
  • What's wrong with `r'\d{3} test'` ? – Austin Jan 21 '20 at 16:45
  • 1
    Does this answer your question? [How to format raw string with different expressions inside?](https://stackoverflow.com/questions/16754594/how-to-format-raw-string-with-different-expressions-inside) – Ryan Schaefer Jan 21 '20 at 16:47
  • "Doesn't work" doesn't tell us anything useful. (If it worked, you wouldn't be asking a question.) – chepner Jan 21 '20 at 16:49
  • The raw string (`r'\d{3} {}'`) doesn't work because it needs to be (`r'\d{{3}} {}'`). `{{` isn't an escape. – Eli Sadoff Jan 21 '20 at 16:51

0 Answers0