-2

Possible Duplicate:
how to make the width and height x2 using python Regular

This is my code:

import re

s = '<img src = "/" width="10" height="111"  />'


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.*?width=\"(\d+)\".*?height=\"(\d+)\"[^>]*>''',a, s)

print ss

and it works properly:

<img src = "/" width="20" height="222"  />

but if I put the height property before the width, like this:

<img src = "/" height="111" width="10" />

It will do nothing.

So I have to do this, trying both possibilities:

import re

s = '<img src = "/" height="111" width="10" />'


def a(x):
    c = x.group(0)
    c = c.replace(x.group(1),str(int(x.group(1))*2))
    return c

def b(x):
    c = x.group(0)
    c = c.replace(x.group(1),str(int(x.group(1))*2))
    return c

ss = re.sub(r'''<img.*?width=\"(\d+)\"[^>]*>''',a, s)
print ss
ss = re.sub(r'''<img.*?height=\"(\d+)\"[^>]*>''',b, ss)
print ss

but my boss told me that it will spend much time.

So what can I do?

Thanks.

Community
  • 1
  • 1
zjm1126
  • 34,604
  • 53
  • 121
  • 166

0 Answers0