Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression, not outputting values correctly

num = re.findall (r'[-+]?\d*\.*\d+' , str (table))

Hi all I have this regular expression and it is printing the values i want. However, they are separated.

For example:

['7', '336.82', '-3.89', '-0.05', '7', '351.60', '7', '322.86', '7', '340.71'] 

is what it prints

But i want it to print:

['7,336.82', '-3.89', '-0.05', '7,351.60', '7,322.86', '7,340.71']

Please could someone help?

Thanks in advance.

like image 208
AmsKumar Avatar asked Apr 16 '26 20:04

AmsKumar


1 Answers

Looks like you want to capture numbers that are separated by comma. You can use:

r'[-+]?(?:\d+[\d,]*)?\.?\d+'

RegEx Demo

like image 102
anubhava Avatar answered Apr 19 '26 12:04

anubhava



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!