I wanted to build a JS function concatting a list of arguments to a valid path (since I could not be sure whether a part of the path is given with or without slashes)
This is the function:
concatPath = function() {
var path = "";
for(var i = 0; i < arguments.length; i++) {
path += arguments[i].replace("(\\|/)$|^(\\|/)", "") + "/";
}
return path;
}
The used RegEx matched all beginning and ending slashes and backslashes on http://regexpal.com But the function does not work properly (RegEx does not match). Furthermore, Chrome states
SyntaxError: Invalid regular expression: /()$|^()/: Unterminated group
when I just use the RegEx
(\\)$|^(\\)
However, using the RegEx
(\\)$|^(\\)
works fine.
Is it too late or did I missed something special?
Thanks in advance!
Leo