I have a string like this:
"https://myEnv.site.org/search?q=searchTerm"
I am trying to get the searchterm.
and I succeded somewhat with this:
const returnValue = url
.split('=')[1]
.replace('+', ' ');
The replace is for when there is a space, like for example when value is SearchTerm withSpace
Im some scenarios I also have this charachter in the searchterm:
Something® Category® version subversion somethingElse
This turn into:
Something%C2%+Category%C2%+version+subversion+somethingElse
I thought I could solve it by doing this:
const returnValue = url
.split('=')[1]
.replace('%C2%AE', '®')
.replace('+', ' ');
Problem is that it only removes the first instance, the new value becomes:
Something® Category%C2%+version+subversion+somethingElse
I have tried a few regex attempts and Ive gotten this far which gives me the wrong result:
const returnValue = url
.split('=')[1]
.replace(/([~!@#$%^&*()_+=`{}\[\]\|\\:;'<>,.\/? ])+/g, '®')
.replace(/^(-)+|(-)+$/g, ' ');
To be clear I want to replace %C2%AE
with ®
and the +
with ' '