Java regex split on whitespace /not preceded

Daniel Jeney :

I would like to split a string:"x= 2-3 y=3 z= this, that" I would split this up on one or more whitespaces, that are not preceded by a '=' or a ',' meaning group one: "x= 2-3" two: "y=3" three: "z= this, that" I have an expression that kinda does it but its only good if = or , has only one whitespace after it.

(?<![,=])\\s+ 
JvdV :

Thinking the other way around (looking forward instead of backwards), would the following do the job for you?

\\s+(?=\\S*=)
  • \\s+ - one or more whitespace characters
  • (?=\\S*=) - positive lookahead to make sure it's followed by as many non-whitespace characters and a literal equal sign.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=4290&siteId=1