C.Shoe C.Shoe - 6 months ago 30
Javascript Question

JS Regex: Double slash splitting along with other characters

I have a split statement in my JavaScript that will split spaces and semicolons, but I want to split double slashes as well. I cannot figure out how to include a double slash along with the space and semicolon.

line = lines[i].split(/[\s;]+/);

Any help is greatly appreciated.


so assuming that by "double slashes" you mean a double forward slash ( "//" ) you are going to want to do something like the following:

line = lines[i].split(/[\s;]+|\/{2}/);

Note that the matching options are being moved from between brackets, because when placed within the brackets, "{", "2", and "}" would be interpreted literally, rather than as a pattern