I am extracting info from a string using regex.
auto version = { // comments shows the expected output
"2012.12", // "2012", "12", "", ""
"2012.12-1", // "2012", "12", "", "1"
"2012.12-SP1", // "2012", "12", "SP1", ""
"2012.12-SP2-1", // "2012", "12", "SP2", "1"
"I-2013.12-2", // "2013", "12", "", "2"
"J-2014.09", // "2014", "09", "", ""
"J-2014.09-SP2-1", // "2014", "09", "SP2", "1"
};
The regex I have is the following:
// J - 2014 . 09 - SP2 - 1
std::regex regexExpr("[A-Z]?-?([0-9]{4})\\.([0-9]{2})-?(SP[1-9])?-?([1-9])?.*");
and this seems to work well. I am not very confident about this since I don't have much expertise in regex. Is the regex right and can this be improved?
Aucun commentaire:
Enregistrer un commentaire