0

With Python I need to replace a text but parts of the text is dynamical created. The start and finish of the string is always the same and unique.

Can I use placeholders inside filedata.replace() or is there a different method to solve that problem?

This did not work:

filedata = filedata.replace('<a href="/link/%s">Link</a>', '<a href="/link/replaced">Link</a>')
Sebastian
  • 75
  • 6

1 Answers1

1

Solution based on the comments under my question:

import re
filedata = re.sub('<a href="/link/(.*?)">Link</a>', '<a href="/link/replaced">Link</a>', filedata)

Read about regular expressions.

Sebastian
  • 75
  • 6