$re = '/magnet:\?((&?xt\.?\d*=urn:[A-Za-z0-9][A-Za-z0-9-]{0,31}:[A-Fa-f0-9]{20,50})|(&?(dn|tr|xl|ws|as|xs|kt|mt)=[A-Za-z0-9\-._%+;=:?\/]+)&?)+$/';
$str = 'magnet:?xt=urn:btih:6B5FFA38E0C811E0738697BEC13DDDA57A60FCB4&dn=Taboo.UK.Season.1.S01.1080p.AMZN.WEBRip.5.1.HEVC.x265-GIRAYS&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2920%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&as=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounc/e&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3/A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&xt=urn:btih:6B5FFA38E0C811E0738697BEC13DDDA57A60FCB4&xt=urn:btih:6B5FFA38E0C811E0738697BEC13DDDA57A60FCB4&xs=dchub://example.org&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawiki-1.15.1.tar.gz&xl=10826029&dn=mediawiki-1.15.1.tar.gz';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php