vibrantsparrow
vibrantsparrow

Reputation: 65

Splitting string with brackets, spaces, and equal signs

I have the following string and I just want to extract "My Important Text".

cssbody=[short_bdy] cssheader=[short_hdr] body=[My Important Text] offsetx=[10] offsety=[20] delay=[300]

Upvotes: 0

Views: 132

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521457

We can try using re.findall with the pattern:

\bbody=\[(.*?)\]

Script:

inp = "cssbody=[short_bdy] cssheader=[short_hdr] body=[My Important Text] offsetx=[10] offsety=[20] delay=[300]"
matches = re.findall(r'\bbody=\[(.*?)\]', inp)
print(matches[0])

This prints:

My Important Text

Upvotes: 1

Related Questions