开发者

Regex Replace [*]

开发者 https://www.devze.com 2023-02-17 02:29 出处:网络
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:

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

精彩评论

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