I'm dealing with a situation where I have strings like #test
or #test?params=something
var regExp = /(^.*)?\?/;
var matches = regExp.exec($(this).data('target'));
var target = matches[1];
console.log(target);
I always want to extract only #test.
However, the current function throws an error if there is no question mark in the string. My objective is to consistently retrieve #test
regardless of any additional parameters. How can I adjust the regex pattern to achieve this?