Having a little trouble with targeting "group of characters that might contain a hypen before" with regex. I'm performing this on a string of query params. I might have something like this:
http://www.example.com?page=5&items=ASC&state=NY
I'm trying to find all the characters before =ASC
, so in this case it would be items
.
Because items
is dynamic, this could change, so would like to be able to target any word that could be placed before =ASC
(including hyphens).
Here are a few examples of other cases I need to meet:
http://www.example.com?status=ASC&state=HI
Should capture status
http://www.example.com?page=5&e-mail=ASC&state=NY
Should capture e-mail
I currently have:
const url = 'http://www.example.com?page=5&items=ASC&state=NY';
const newUrl = url.replace(/[a-zA-Z0-9-]=(?=ASC)/, 'test');
but it's not working.
Any and all help would be greatly appreciated.