In regex, match either the end of the string or a specific character

Use:

/(&|\?)list=.*?(&|$)/

Note that when you use a bracket expression, every character within it (with some exceptions) is going to be interpreted literally. In other words, [&|$] matches the characters &, |, and $.

Leave a Comment