I want to make a simple home made bbcode.
Example of a string :
s = 'Hello world, this is my website {url}myURL{/url}'
I want to replace {url}myURL{/url} by <a href="myURL">myURL</a>
It will be great if someone has the solution ?
I want to make a simple home made bbcode.
Example of a string :
s = 'Hello world, this is my website {url}myURL{/url}'
I want to replace {url}myURL{/url} by <a href="myURL">myURL</a>
It will be great if someone has the solution ?
Python String replace() Method
The
replace() methodreplaces a specified phrase with another specified phrase.Note: All occurrences of the specified phrase will be replaced, if nothing else is specified.
Syntax:
string.replace(oldvalue, newvalue, count)
s = 'Hello world, this is my website {url}myURL{/url}'
print (s.replace('{url}', '<a href="').replace('{/url}','">myURL</a>'))
output:
Hello world, this is my website <a href="myURL">myURL</a>