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)
<
Try this... it's a little easier to follow with the [character classes]. to match a single \
with a javascript string you need \\\\
, which may be what's going on.
new Regexp('^[\\\\/]|[\\\\/]$')
You can also try the /^[\\\/]|[\\\/]$/g
notation.
s = 'c:\\folder\\'
console.log(s.replace(/^[\\\/]|[\\\/]$/g, ''))