java - using regex to split string -
i want string "initial: at(forest), monsterat(chimera,forest), alive(chimera)" parsed into: "at(forest)" , "monsterat(chimera, forest)" , , "alive(chimera)" (i don't need "initial:").
i used code (java - split string using regular expression):
string[] splitarray = subjectstring.split( "(?x), # verbose regex: match comma\n" + "(?! # unless it's followed by...\n" + " [^(]* # number of characters except (\n" + " \\) # , )\n" + ") # end of lookahead assertion");
this output (the underscore space):
initial: at(forest) _monsterat(chimera,forest) _alive(chimera)
but don't want have space before string ("_alive(chimera)"), , want remove "initial: " after splitting. if removed spaces (except "initial") original string output this:
initial: at(forest),monsterat(chimera,forest),alive(chimera)
you can whole thing in 1 line this:
string[] splitarray = str.replaceall("^.*?: ", "").split("(?<=\\)), *");
this works splitting on commas following closing brackets, after removing initial input ending in colon-space.
Comments
Post a Comment