Do i have to escape slashes when putting them into regular expression?
myString = \'/courses/test/user\'; myString.replace(/\\/courses\\/([^\\/]*)\\/.*/, \"$
string.replace doesn't modify the original string. Instead, a returns a new string that has had the replacement performed.
string.replace
Try:
myString = '/courses/test/user'; document.write(myString.replace(/\/courses\/([^\/]*)\/.*/, "$1"));