I have this string: #test
or #test?params=something
var regExp = /(^.*)?\?/;
var matches = regExp.exec($(this).data('target'));
var target = matches[1];
console.log(target);
I always need to get only #test.
The function I pasted returns an error if no question mark is found. The goal is to always return #test
whether there are additional params or not. How do I make a regex that returns this?