I have this string (it's part of a file):
{
return array(
'major' => '1',
'minor' => '9',
'revision' => '1',
'patch' => '1',
'stability' => '',
'number' => '',
);
}
I need to form a proper version number out of this, in this case "1.9.1.1". I have already written the code doing this, but I would like to know if there is a better, more beautiful solution, or one that requires less code. I've been thinking about using a more complex regular expression that returns all parts of the version number, but I couldn't figure out how, and returning a match like "1911" might cause more trouble than its worth when there's a two-digit number involved, e.g. "1.10.1.1". In this case it would be impossible to know where to split the "11011" as it might as well be "11.0.1.1" or "1.1.0.11".
Here's what I've got (in Python code):
result = []
result.append(re.search("'major'\\s+=>\\s+'(\\d+)'", text))
result.append(re.search("'minor'\\s+=>\\s+'(\\d+)'", text))
result.append(re.search("'revision'\\s+=>\\s+'(\\d+)'", text))
result.append(re.search("'patch'\\s+=>\\s+'(\\d+)'", text))
str = ""
for res in result:
if res:
str += res.group(1) + "."
return str[:-1]