I want to remove part of the string between two special characters (#
and ?
) including the hash character but NOT including the question mark, so url#hash?param=2
becomes url?param=2
I was able to come up with something like
str.replace( /#.*??/, '?' );
The only problem is when string ends with something like url#hash
which leaves me hanging with trailing question mark. How do I exclude question mark itself from replacement?