Andre
Andre

Reputation: 1107

Regex Replace [*]

I have a string as follows:

something.something[0].somethingelse[21].blah

I want to replace all the [*] section with an empty string so that I end up with a string like this:

something.something.somethingelse.blah

(I'm doing this in Python if that makes any difference)

Upvotes: 0

Views: 487

Answers (3)

Gary Hughes
Gary Hughes

Reputation: 4510

import re

p = re.compile(r'\[[0-9]+\]')
s = 'something.something[0].somethingelse[21].blah'

print p.sub('', s)

Upvotes: 4

Marcom
Marcom

Reputation: 4741

this should work

\[\d*\]

and replace with ""

Upvotes: 0

BoltClock
BoltClock

Reputation: 724182

Try this:

re.sub(r'\[\d+\]', '', 'something.something[0].somethingelse[21].blah')

Upvotes: 6

Related Questions