$re = '/^([r])([1-9A-HJ-NP-Za-km-z]{24,34})$/m';
$str = '// valid addresses
rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn
r9kiSEUEw6iSCNksDVKf9k3AyxjW3r1qPf
rs2qdz5stxyWeMk6sNz5mLY6h5xxPYNJ8u
rfe8yiZUymRPx35BEwGjhfkaLmgNsTytxT
rPE9dw1gR8ravY2o25zudXmj2L28UTNt4D
r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X
// invalid addresses (with O, I, l or 0)
rPE9dw1gR8ravY2o25zudXmj2L20UTNt4D
r9vbV3EHvXWjSkeQ6CAcYVPGel7TuiXY2X
r9vbV3EHvXWjSkeQ6CAcYVPGeqOTuiXY2X
r9vbV3EHvXWjSkeQ6CAcYVPGeqITuiXY2X
';
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