testString = "something://something/task?type=Checkin";
patt = new RegExp("something\/(\w*)\?");
match = patt.exec(testString);
document.querySelector('#resultRegexp').innerHTML = match[1];
I want to capture task So shouldn’t this RegExp work?
I am grabbing any alphanumeric character up until the question mark… and capturing it.
You would need to escape the slash in regex literals, and the backslash in string literals which you create regexes from:
I strongly recommend the first version, it is more readable.