I'm trying to create a method which takes a String parameter and then returns a two dimensional String array of parameter names and values.
protected final String[][] setParams (String parms) {
String[][] params;
int i = 0;
Pattern p = Pattern.compile(NEED_REGEX_HERE);
Matcher m = p.matcher(parms);
params = String[m.groupCount()][2];
while (m.find()) {
params[i][0] = m.group(i).subString(0,m.group(i).indexOf('='));
params[i][1] = m.group(i).subString(m.group(i).indexOf('='));
i++;
}
return params;
}
Some examples of input would be (inside quotes):
"Name=Ryan;\;Name=John"
"Name=Ryan;Name=John"
"Name=Ryan"
"Name=Ryan;Index=1"
So a ";" is the list delimeter and the assignment operator "=" denotes a valid parameter ie. "\" is a throw away value. Basically I'm looking for a regex that will allow me to do this, or if someone can provide one, a more elegant solution.