From: Terry Reedy on 18 May 2010 13:11 On 5/18/2010 10:40 AM, J. Cliff Dyer wrote: > Don't use regular expressions for that. > > s = '0x340x5A0x9B0xBA' > return '0x' + ''.join(s.split('0x')) or >>> '0x'+s[2:].replace('0x','') '0x345A9BBA' Take your pick, you should learn and understand both. > On Tue, 2010-05-18 at 06:48 -0700, Back9 wrote: >> Hi, >> >> I have a string like this: >> 0x340x5A0x9B0xBA >> I want to extract 0x from the string but the first one. >> >> How I can use re for this case? >> >> The string size will vary. >> >> TIA >> > >
From: Anthra Norell on 19 May 2010 03:26
Back9 wrote: > Hi, > > I have a string like this: > 0x340x5A0x9B0xBA > I want to extract 0x from the string but the first one. > > How I can use re for this case? > > The string size will vary. > > TIA > > Unless the use of a regular expression is a requirement I'd do it like this: '0x%s' % s.split ('x', 1)[1].replace ('x', '') Frederic |