Using re.sub with %s

B

Brandon Harris

Having trouble using %s with re.sub

test = '/my/word/whats/wrong'
re.sub('(/)word(/)', r'\1\%s\2'%'1000', test)

return is /my/@0/whats/wrong

however if I cast a value with letters as opposed to numbers

re.sub('(/)word(/)', r'\1\%s\2'%'gosh', test)

return is /my/gosh/whats/wrong


Any help would be good. I've tried passing the value as an int, or
recasting that value as something else, passing it as a raw string,
removing the r and just double escaping the groups.

Brandon L. Harris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top