Arun
Arun

Reputation: 13

I want to extract a specific value from a string in python

I have a string from which I want to extract value for test1. The string is :

I_ID [I_ITEM = [I_ITEM [test1 = F135], I_ITEM [test1 = W1972544]]]]]

Any pointers will be helpfull

Upvotes: 0

Views: 93

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520978

Assuming you want to capture all values whose keys are test1, we can try using re.findall:

inp = "I_ID [I_ITEM = [I_ITEM [test1 = F135], I_ITEM [test1 = W1972544]]]]]"
values = re.findall(r'\btest1\s*=\s*(.*?)\]', inp)
print(values)  # ['F135', 'W1972544']

Upvotes: 1

Related Questions