regex - Java - Tokenize Parameter List -
I am trying to create a method that takes string parameters and then returns two-dimensional string array of parameter names and values is .
protected last string [] [] set param (string params) {string [] [] params; Int i = 0; Pattern p = Pattern.compile (NEED_REGEX_HERE); Mitcher M = P. Matches (Parameters); Parameters = string [m.groupCount ()] [2]; While (m.find ()) {params [i] [0] = MGP (I) .subString (0, M.G.P. (I) .indexOf ('=')); Paramaze [I] [1] = MGroup (i) .subString (m.group (i) .indexOf ('=')); I ++; } Return the ultimate; }
Some examples of input (inside quotes) will be:
"name = ryan; \; name = John" "name = ryan; name = "John" "name = Ryan" "name = Ryan; Index = 1 "
one"; "Delimiter and assignment operator of the list" = "is a valid parameter." \ "Is a throw value. Actually I see for a regex I am allowed to do this, or if one can provide a more elegant solution.
For two given examples, two partitions should work:
string [] keyValuePairs = line.split (";"); for string value Ire: keywallpair) {ifThrowAwayParameter (keyValuePair)} {handleThrowAwayParameter ();} and {string [] key and = value = rice = Pair.split ("="); string key = key and value [0]; string value = Key and value [1]; handle and endowue (key, value);}}
Comments
Post a Comment