有这样两个各变量
$str1 = "eA株式会社 <[email protected]>";
$str2 = "eA株式会社 ([email protected])";
这两种格式正确。我需要验证当$str1 = "eA株式会社 <[email protected])";或者$str1 = "eA株式会社 <[email protected]";
$str2 = "eA株式会社 ([email protected]>";或者$str2 = "eA株式会社 ([email protected]";
时输出false;
请问正则能匹配出来吗?帮忙老师们写个..3q
$str1 = "eA株式会社 <[email protected]>";
$str2 = "eA株式会社 ([email protected])";
这两种格式正确。我需要验证当$str1 = "eA株式会社 <[email protected])";或者$str1 = "eA株式会社 <[email protected]";
$str2 = "eA株式会社 ([email protected]>";或者$str2 = "eA株式会社 ([email protected]";
时输出false;
请问正则能匹配出来吗?帮忙老师们写个..3q
好像不行啊?..是这样/^eA株式会社 <[A-Za-z0-9]+\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/ ?
那个eA株式会社我可能会换成别的名字,不一定就是eA株式会社,可能是xxxxx,刚才发帖没说清。\w可以替换eA株式会社吧?
$onlyconsonants = str_replace($vowels, "", "eA株式会社 <[email protected]>",$count);echo $count;//2上面那个正则只有继续关注,不过可以提供个方法给你参考参考
/^eA株式会社 <[A-Za-z0-9]+\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
我上面的式子可匹配 [email protected] 或[email protected] /^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/ 这个可以满足你的要求。你测试测试。
[email protected]我以为你会在我式子上改改,所以就只是复制粘贴而已。
<?php
$str1 = "eA株式会社 <[email protected]>";
$str2 = "eA株式会社 <[email protected]";
$str3 = "eA株式会社 <[email protected])";
$str4 = "eA株式会社 ([email protected])";
$str5 = "eA株式会社 ([email protected]";
$str5 = "eA株式会社 ([email protected]>";var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str1));
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str2));
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str3));
//匹配小括号start
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str4));
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str5));
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str6));
//匹配小括号end
?>对正则不了解,学习中,请见谅。$str2那个匹配出来了,但是我有问题
1.就是能不能把那个正则中的“eA株式会社”写个共通的?我写成\w就匹配不出来了,文字是日文的。
2.那个小括号的好像不行,
//匹配小括号start
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str4));
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str5));
var_dump(preg_match("/^eA株式会社 <[A-Za-z0-9]+\.[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$/", $str6));
//匹配小括号end是不是要把<换成\( ?多谢解答。
<?php
$str1 = "eA株式会社 <[email protected]>";
$str2 = "eA株式会社 <[email protected])";
$str3 = "eA株式会社 <[email protected]";
$str4 = "[email protected] (eA株式会社)";
$str5 = "[email protected] (eA株式会社>";
$str5 = "[email protected] (eA株式会社";
if (preg_match('/^(.*)<([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})>$/i', $str1)) {
# Successful match
} else {
# Match attempt failed
}
if (preg_match('/^([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})( *)\((.*)\)$/i', $subject)) {
# Successful match
} else {
# Match attempt failed
}
if (preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $subject)) {
# Successful match
} else {
# Match attempt failed
}
?>
这个应该满足要求了。测试中。。