[Solved] Regex for finding the second occurrence of a character in a dynamic string in javascript


const regex = /(.*?&.*?)&.*/;
const str = `https://www.bing.com/search?q=something+something+something+something&mkt=en-IN&organic=True&ads=False&snippet=False`;


const result = str.replace(regex, '$1');

The regular expression searches everything before the second “&” and replaces the original string with this match.

solved Regex for finding the second occurrence of a character in a dynamic string in javascript