I was using python 3.7 and the re library to find values in a csv file like
23,"1,309",0
23,"134,799",2
,"1,549,089",0
8908.89,"27,989",3
The values I wanted to extract are the ones surrounded by double quotes and with commas as thousand separators. Before doing it, I tested the following regex in VS Code search:
"(\d+,)?\d+,\d+"
Which highlighted the right matches. However, when I used the regex in python:
regex = r'"(\d+,)?\d+,\d+"'
re.findall(regex, text)
I got:
['', '', '1,', '']
At length, I was able to get the right matches by using this expression instead:
regex = r'"\d+,\d+,\d+|\d+,\d+"'
But I am curious to know why the first expression worked in VSCode but not in Python. Why would that be?