Daniel wrote: > Hello all > > I need to build a program that check the sintax in a line: > > SIZE (1 BYTE) > > and change the correct number of bytes to the following format: > > SIZE(1) > > without the "BYTE" word. But, the number of bytes can be over 3 digits, > and the entitie can't have spaces but the correct number of bytes in > parentheses, like "SIZE (1024 BYTE)" to "SIZE(1024)".
>>> import re >>> byter = re.compile(r'SIZE \((\d+) BYTE\)') >>> s = 'SIZE (1 BYTE)' >>> byter.sub(r'SIZE(\1)', s) 'SIZE(1)' >>> s = 'SIZE (1024 BYTE)' >>> byter.sub(r'SIZE(\1)', s) 'SIZE(1024)' Kent -- http://mail.python.org/mailman/listinfo/python-list