Dec-06-2022, 07:00 AM
Hi, I would like to know if there is a way to validate the '{}' when I receive them in a function. For example, I receive a URL and I have two parameters and I can perfectly do the .format. However, what if I have several URLs and some of them have the following model:
Thank you!
import re def test(param): # I need here know how many {} I will receive print(param.format("google.com", "webpath")) test("http://{}/something/{}") # What's happen if I will do the next? #test("http://{}/something/{}/{}/{}/{}")It is for this reason, that maybe it could be done with re.replace, but it seems to me a rudimentary way and even so, I think it would not solve the problem:
import re def test(param): print(param.format(param.replace('[host]', 'a'), param.replace('[path]',"b"))) test("http://[host]/something/[path]")Any ideas?
Thank you!