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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -