How can I edit this code to handle multiple delimiters? Currently, it checks for either %7
or |relevance
and removes it. But it does not handle multiple delimiters such as in the 2 URL examples below.
https://www.example.com/en-us/search?pq=marketing+agriculture%7Crelevance%7CbestSeller%3Atrue
https://www.example.com/en-us/search?pq=marketing+agriculture|Crelevance|CbestSeller%3Atrue
It should only grab the words: marketing agriculture from the two URLs above.
const params = new URLSearchParams(window.location.search);
if (params.has('pq')) {
const pq = params.get('pq').split('&7').pop().replace('|relevance', '');
console.log(pq);
}
Desired output: To get only the search terms from the URL.