i have to do many work to change like this:
<img src = "/" height="111" width="10" />
to
<img src = "/" height="222" width="20" />
so i want to use python Regular
this is my code :
import re
s = '<img src = "werwerwe" height="111" width="10" />'
def a(x):
print x.group(2)
print x.group(4)
ss = re.sub(r'''<img.*(widths*="?(d+)"?)*s*(heights*="?(d+)"?)*''',a, s)
print ss
so what can i do ,
thanks
updated:
it is ok now :
import re
s = '<img src = "/" height="111" width="10" />'
def a(x):
b = x.group(0)
b = b.replace(x.group(1),str(int(x.group(1))*2))
b = b.replace(x.group(2),str(int(x.group(2))*2))
return b
ss = re.sub(r'''<img.*?height="(d+)".*?width="(d+)"[^>]*>''',a, s)
print ss
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…