dimanche 22 février 2015

Replace unknown alphanumeric character in string in Python

I have the below aspect of a string:-



"a*.b*"



The '*' represents an unknown alphanumeric character as this data is being scraped and so the aspect of the string could be "a1.b1" or "az.bz" for example. Likewise, this appears in a longer piece of string and so could appear in :



"http://www.a*.b*.com" where '*' = '1'.


The lengths of the strings are unknown.


What I want to do is that for each time the pattern 'a*.b*' is encountered within the string (where '*' is an alphanumeric character, I wish for the letter 'a' to be replaced with 'z' so:-



'a1.b1' becomes 'z1.b1' and 'a4.b1' becomes 'z4.b1'



As said, the above features WITHIN a string.


Any advice?


Aucun commentaire:

Enregistrer un commentaire