javascript regex split produces too many items

后端 未结 4 1848
野的像风
野的像风 2020-11-27 08:32

I\'m trying to split a string using either commas or whitespace. A comma can optionally be preceded and/or followed by whitespace, and whitespace by itself also counts as a

4条回答
  •  情深已故
    2020-11-27 09:06

    With regexes the capture expression (x) remembers the match (and possibly returns that to the String.split). You should use the (non-capturing) grouping expression (?:x). See e.g. the Mozilla Docs on RegExp for more.

提交回复
热议问题