开发者

Get data from string

开发者 https://www.devze.com 2023-02-17 07:22 出处:网络
i have a string like A & A COMPUTERS INC [RC1058054] i want a regex 开发者_JS百科to split all the data inside [ ].Any ideas ?To capture the data between [ and ] you can use the regex:

i have a string like

A & A COMPUTERS INC [RC1058054]

i want a regex 开发者_JS百科to split all the data inside [ ] .Any ideas ?


To capture the data between [ and ] you can use the regex:

\[([^]]*)\]


Since the current version of the question leaves out the programming language, I just pick one.

>>> import re
>>> s = "A & A COMPUTERS INC [RC1058054]"
>>> re.search("\[(.*)\]", s).group(1)
'RC1058054'

>>> # If you want to "split all data" ...
>>> [ x for x in re.search(s).group(1) ]
['R', 'C', '1', '0', '5', '8', '0', '5', '4']


This regex (?<=\[)[^]]*(?=\]) capture all data between [ and ] for .net and java platform.

0

精彩评论

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