Split a string based on multiple delimiters

前端 未结 6 2142
情深已故
情深已故 2020-11-29 06:12

I was trying to split a string based on multiple delimiters by referring How split a string in jquery with multiple strings as separator

Since multiple delimiters I

6条回答
  •  一个人的身影
    2020-11-29 06:58

    The following would be an easier way of accomplishing the same thing.

    var tokens = x.split(new RegExp('[-+()*/:? ]', 'g'));​​​​​​​​​​​​​​​​​
    

    Note that - must come first (or be escaped), otherwise it will think it is the range operator (e.g. a-z)

提交回复
热议问题