javascript - Split a string based on multiple delimiters -
i trying split string based on multiple delimiters referring how split string in jquery multiple strings separator
since multiple delimiters decided follow
var separators = [' ', '+', '-', '(', ')', '*', '/', ':', '?']; var tokens = x.split(new regexp(separators.join('|'), 'g'));
but i'm getting error
uncaught syntaxerror: invalid regular expression: / |+|-|(|)|*|/|:|?/: nothing repeat
how solve it?
escape needed regex related characters +,-,(,),*,?
var x = "adfds+fsdf-sdf"; var separators = [' ', '\\\+', '-', '\\\(', '\\\)', '\\*', '/', ':', '\\\?']; console.log(separators.join('|')); var tokens = x.split(new regexp(separators.join('|'), 'g')); console.log(tokens);
Comments
Post a Comment