user339160
user339160

Reputation:

Get data from string

i have a string like

A & A COMPUTERS INC [RC1058054]

i want a regex to split all the data inside [ ] .Any ideas ?

Upvotes: 0

Views: 84

Answers (3)

Gursel Koca
Gursel Koca

Reputation: 21290

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

Upvotes: 0

miku
miku

Reputation: 188004

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']

Upvotes: 1

codaddict
codaddict

Reputation: 454960

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

\[([^]]*)\]

Upvotes: 1

Related Questions