I am trying to find all the parameteres-values from a string with the following form:
pN stands for the Nth parameter: it can be composed of the following chars:
letters, numbers, and any char included in kSuportedNamesCharsRegEx
vNX for the the Xnt component of the value of the Nth parameter
vNX accepts arithmetical expressions. Therefore I have constructed kSuportedValuesCharsRegEx. Additionally, it could allow simple/nested list as the value.
Here is an example of the string to be parsed
p1 p2 = (v21 + v22) p3=v31-v32 p4 p5=v5
where I should obtain "p1", "p2 = (v21 + v22)", "p3=v31-v32", "p4", "p5=v5"
As it can be seen, the parameters may have or may not have a value. I am using c++ boost libraries (so I think I don't have available look behind). Till now, I onlye had to deal with parameters which have value, so I have been using the following:
static const std::string kSpecialCharsRegEx = "\\.\\{\\}\\(\\)\\\\\\*\\-\\+\\?\\|\\^\\$";
static const std::string kSuportedNamesCharsRegEx = "[A-Za-z0-9çÇñÑáÁéÉíÍóÓúÚ@%_:;,<>/"
+ kSpecialCharsRegEx + "]+";
static const std::string kSuportedValuesCharsRegEx = "([\\s\"A-Za-z0-9çÇñÑáÁéÉíÍóÓúÚ@%_:;,<>/"
+ kSpecialCharsRegEx + "]|(==)|(>=)|(<=))+";
static const std::string kSimpleListRegEx = "\\[" + kSuportedValuesCharsRegEx + "\\]";
static const std::string kDeepListRegEx = "\\[(" + kSuportedValuesCharsRegEx + "|(" + kSimpleListRegEx + "))+\\]";
// Main idea
//static const std::string stackRegex = "\\w+\\s*=\\s*[\\w\\s]+(?=\\s+\\w+=)"
// "|\\w+\\s*=\\s*[\\w\\s]+(?!\\w+=)"
// "|\\w+\\s*=\\s*\\[[\\w\\s]+\\]";
// + deep listing support
// Main regex
static const std::string kParameterRegEx =
+ "\\b" + kSuportedNamesCharsRegEx + "\\b\\s*=\\s*" + kSuportedValuesCharsRegEx + "(?=\\s+\\b" + kSuportedNamesCharsRegEx + "\\b=)"
+ "|"
+ "\\b" + kSuportedNamesCharsRegEx + "\\b\\s*=\\s*" + kSuportedValuesCharsRegEx +"(?!" + kSuportedNamesCharsRegEx + "=)"
+ "|"
+ "\\b" + kSuportedNamesCharsRegEx + "\\b\\s*=\\s*(" + kDeepListRegEx + ")";
However, now that I need to deal with non-valued parameters, I am having troubles creating the correct regex.
Could someone help me with this problem? Thanks in advance