开发者

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)


Try this:

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


import re

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

print p.sub('', s)


this should work

\[\d*\]

and replace with ""

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜