阿拉伯语电子邮件地址的正则表达式



>已编辑

我用谷歌搜索为我的 Web 应用程序编写了一个自定义正则表达式,但我仍然无法得到我想要的东西。

我想检查字符串是否通过此模式:

*STRING*STRING INCLUDING ALL CHARS*STRING INCLUDING ALL CHARS#

例如:

*STRING*the first string تست یک*the second string تست دو#

应返回 TRUE

*sdsdsd*the first string تست یکthe second string تست دو#

应该返回 FALSE(因为它不是 *字符串*字符串*字符串#的模式)

$check = preg_match("THE RULE", $STRING);

在这里要求规则,对不起,如果我以错误的方式问了我的问题......

不需要正则表达式,使用 filter_var()

function checkEmail($str){
    $exp = explode('*', $str);
    if(filter_var($exp[1], FILTER_VALIDATE_EMAIL) && $exp[2] && $exp[3] && substr($str, strlen($str)-1, strlen($str)) == '#') {
        return true;
    }
    return false;
}
$valid = checkEmail('*example@example.com*the first string تست یک*the second string تست دو#');

要检查字符串是否具有此模式: *STRING*STRING*STRING#

if (preg_match(
    '/^       # Start of string
    *        # Match *
    ([^*]*)   # Match any number of characters except *
    *        # Match *
    ([^*]*)   # Match any number of characters except *
    *        # Match *
    ([^#]*)   # Match any number of characters except #
    #        # Match #
    $         # End of string/x', 
    $subject, $matches))

然后使用

filter_var($matches[1], FILTER_VALIDATE_EMAIL)

以检查第一个组是否可能包含电子邮件地址。

最新更新