Take the 2-minute tour ×  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 = "";         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!   share|improve this question  2 Answers 2
up vote 3 down vote accepted  You should use a regular
expression literal (/.../) instead of a string literal ('...' or
"...") in the call to replace. Strings have their own
interpretation of backslashes that kicks in before the regular