$re = '/^(?:https?:\/\/)((?:www\.)|(?:m\.))?soundcloud\.com\/[a-z0-9](?!.*?(-|_){2})[\w-]{1,23}[a-z0-9](?:\/.+)?$/m';
$str = 'Use only numbers, lowercase letters, underscores, or hyphens.
Profile URLs must not start or end with an underscore or hyphen.
Profile URLs must not have two consecutive underscores or hyphens.
Profile URLs must be between 3 and 25 characters.
http://www.soundcloud.com/fo
http://www.soundcloud.com/foo
https://m.soundcloud.com/abcd123
https://soundcloud.com/abcd123
https://soundcloud.com/
https://m.soundcloud.com/abcd123_l
https://soundcloud.com/abcd123-l
http://www.soundcloud.com/-abcd123
http://www.soundcloud.com/_abcd123
https://m.soundcloud.com/abcd123-_l
https://m.soundcloud.com/abcd123--l
https://m.soundcloud.com/1234567890123456789012345
https://m.soundcloud.com/12345678901234567890123456
https://m.soundcloud.com/1234567890123456789012345/fooo12;lkflkjlfjkljskljflks/
https://m.soundcloud.com/12345678901234567890123456/fooo
http://www.m.soundcloud.com/abcdef';
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