Regular expression

B

Back9

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
 
I

ilvecchio

 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
 
J

J. Cliff Dyer

Don't use regular expressions for that.

s = '0x340x5A0x9B0xBA'
return '0x' + ''.join(s.split('0x'))
 
A

Anthra Norell

Back9 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,172
Messages
2,570,935
Members
47,479
Latest member
JaysonK723

Latest Threads

Top