Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python parsing integers inside parantheses in a string

Tags:

python

I want to parse a simple string with python as -

Limits paramA : (7, 45) paramB : (0, 0) paramC : (1, 23)

I want to extract 7, 45, 0, 0, 1, 23 in different integers. Could someone tell me how can I extract this?

There are lot of string parsing questions in the forum, but I am not able to find the answer that suits me best.

Thank You.

like image 511
Raj Avatar asked Nov 24 '25 02:11

Raj


1 Answers

using regex:

In [71]: import re

In [72]: strs="Limits paramA : (7, 45) paramB : (0, 0) paramC : (1, 23)"

In [74]: [int(digit) for digit in re.findall(r'\d+',strs)]
Out[74]: [7, 45, 0, 0, 1, 23]
like image 106
Ashwini Chaudhary Avatar answered Nov 25 '25 17:11

Ashwini Chaudhary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!