skij
asked on
JavaScript/REGEX: replace to matching character OR through end of string
Using JavaScript and regular expressions, how can I replace the section of a string that ends with a specific character OR if that character is not used then to replace through the end of the string?
alert( zap('x=1&y=2&z=3')); // this works
alert( zap('x=1&y=2')); // this does not work
function zap (str) {
return str.replace(/y=(.*)\&/g, '');
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.