I have a
import re
s = """
/* comments */
vector<CWaypoint> Vparam; // comment
int cValue=2049; // comment
double param=0.01; // comment
"""
exp = re.compile(r"(?:\s|\b)(.+?)=(.+?)\b;")
print(exp.findall(s))
My expected output is
[(cValue,2049), (param,0.01)]
but why am I getting the data type before the variable name like below
[('int cValue', '2049'), ('double param', '0.01')]
Why isn't boundaries working even if they are non greedy
(.+?)=to(\w+)=to get what you want. (Though I don't think parsing code with regex is a good idea).(\S+), which matches non-space characters (again, this is very poor approximation, and you should consult the documentation for the exact character set)..makes so much of a difference?\b.+?=.+?\b;matchesint cValue=2049, it is returned as a match.\S+or\w+basically forces the content before=to contain no space, so you only get the variable name.