From: Back9 on 18 May 2010 09:48 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: ilvecchio on 18 May 2010 10:09 On May 18, 3:48 pm, Back9 <backgoo...(a)gmail.com> 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 Maybe the easy way is something like this: m = re.match('(0x)(.*)','0x340x5A0x9B0xBA') m.groups()[1] Terenzio
From: Back9 on 18 May 2010 10:32 On May 18, 10:09 am, ilvecchio <terenzio.be...(a)gmail.com> wrote: > On May 18, 3:48 pm, Back9 <backgoo...(a)gmail.com> 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 > > Maybe the easy way is something like this: > > m = re.match('(0x)(.*)','0x340x5A0x9B0xBA') > m.groups()[1] > > Terenzio I mean the result should be like this: 0x345A9BBA
From: Jon Clements on 18 May 2010 10:37 On 18 May, 15:32, Back9 <backgoo...(a)gmail.com> wrote: > On May 18, 10:09 am, ilvecchio <terenzio.be...(a)gmail.com> wrote: > > > > > On May 18, 3:48 pm, Back9 <backgoo...(a)gmail.com> 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 > > > Maybe the easy way is something like this: > > > m = re.match('(0x)(.*)','0x340x5A0x9B0xBA') > > m.groups()[1] > > > Terenzio > > I mean the result should be like this: > 0x345A9BBA Something like: re.sub(r'\B(0x)', '', s) hth, Jon.
From: J. Cliff Dyer on 18 May 2010 10:40
Don't use regular expressions for that. s = '0x340x5A0x9B0xBA' return '0x' + ''.join(s.split('0x')) 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 > |