Get data from string
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.
精彩评论