Regex to capture either, or, or both -- ampersand help needed

Here’s the pattern I’m working with:

$pattern = 'index.php\\?module=([\\w\\d\\.\\:\\_\\/]+)&(?:amp;)level=([\\w\\d\\.\\:\\_\\/]+)&(?:amp;)id=([\\w\\d\\.\\:\\_\\/]+)"|';

This does match with URLs that have the ampersand encoded in them (&), but for URLs that have a hard ampersand (&), it doesn’t match. I need the pattern to match for both cases.

Can anyone point out a way to amend this pattern so that URLs with hard ampersands AND encoded ampersands are both matched?

Thank you,



should be




Both work

thanks, appreciate that!! :slight_smile: