C.Shoe C.Shoe - 1 year ago 95
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download