$schemes = [
'MASTERCARD' => [
'/^5[1-5][0-9]{14}$/',
'/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/',
]
];
$flag= null;
$data= '123456';
array_walk($schemes['MASTERCARD'], function(&$v, $k) use($flag, $data){
if(!empty($flag)) return;
$flag= preg_match($v, $data);
});
if(!empty($flag))
echo "OK!";
else
echo "FAIL!";
$data= '123456';
preg_replace($schemes['MASTERCARD'], 'OK', $data, 1, $success);
if($success)
echo "OK!";
else
echo "FAIL!";
console.log(/name=([\"\'])([^\"\']+)\1/.exec('<span name="two">text</span>')[2]);
function _getAttr (str, attr) {
return new RegExp(attr + "\s*=\s*([\"\'])([^\"\']+)\\1").exec(str)[2];
}
console.log(_getAttr('<span name="two">text</span>', 'name'));
<?php
$str= ".class{padding:10px 5px;color:#fff;padding:50px!important;background:#000;padding:10px;}";
preg_match("/^([^\{]+){/", $str, $strOut);
$strOut= $strOut[0];
echo "<h5>Исходная строка:</h5> $str <hr>";
preg_match_all("~([^\{\;]+?)\:([^\;\}]+)~i", $str, $out);
$arr= [];
foreach($out[1] as $i => $p) {
if(!in_array($p, $arr)) {
// echo 'Unik - ' . $p . '<br>';
$strOut.= $p . ':' . $out[2][$i] . '; ';
$arr[]= $p;
}
}
echo '<hr>$arr=<br>';
print_r ($arr);
echo '<h5>Результат:</h5>' . $strOut;
?>