一些简单的正则验证

2017-03-02 10:46:23

一些简单的正则验证
$s = "aabcv";
//检查字符串是否为字母,为真不执行,否则输出NO
if(!preg_match("/^[[:alpha:]]+$/",$s))
{
 echo "NO";
}
$s2 = "aaaA";
//检查字符串是否为大写或为小写
//这是大写,必须全部是大写
if(preg_match("/^[[:upper:]]+$/",$s2))
{
 echo "upper";
}
//这是小写,如果字符串中包含一个小写字母的话,,下面这判断就为真
if(preg_match("/[[:lower:]]/",$s2))
{
 echo "lower";
}
//匹配A链接
$a = 'ddsfs';
preg_match('/]href="(.*?=(.*?))">.+/',$a,$c);
//preg_match_all('/]href="(.*?=(.*?))">@.*?/i',$a,$c);匹配多个。
print_r($c);
echo $c[2];
//匹配第一个空格前的内容起始是@
$a = "@test asdfasdf lkj;asdf @testsdfadfadsfa";
preg_match_all("~@([wd_--]+)~",$a,$b);
//preg_match_all('~#([^#]+?)#~',$content,$match);//匹配#内容#
print_r($b);
result:
Array
(
    [0] => Array
        (
            [0] => @test
            [1] => @testsdfadfadsfa
        )

    [1] => Array
        (
            [0] => test
            [1] => testsdfadfadsfa
        )

)

发表评论:

Powered by PHP 学习者(mail:517730729@qq.com)

原百度博客:http://hi.baidu.com/ssfnadn

备案号:闽ICP备17000564号-1

开源中国 PHPCHINA