为什么这个例子中两个正则表达式对邮件的评估方式不同?单词边界和字符串开始和字符串锚点结束(正则表达式)有什么区别?
http://codepad.viper-7.com/SEgMzZ
<?php
$email = 'ΘΘΘ[email protected]';
$regex = '#\b[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}\b#i';
$regex2 = '#^[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}$#i';
if (preg_match($regex, $email)) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
if (preg_match($regex2, $email)) {
echo "A match was found.";
} else {
echo "A match was not found.";
}
?>
编辑:我希望这两个以不匹配
可能希望在你的问题中记下你不期望与之匹配的内容,因为Theta不在你的角色类中用于有效的电子邮件。 –