php知识点复习之正则表达式

//正则表达式的技术知识


//  []定义字符集和 example [a-z]  [A-Z]  [0-9] [\f\r\n\t]


//定位符^[A-Z][0-9]$开头结尾


//量词  *  +  ?  {n}  {m,n}  {n.}指的都是重复次数


//选择 |


//可打印字符:ASCII中33-127表示的字符,就是我们看得见的符号 空格,删除,回车,取消等等就典型的是不可打印字符


//POSiX正则表达式
//常用函数
echo "<br>";
$b4 = "abc";
$pattern = "[[:alpha:]]";
echo ereg($pattern,$b4);
//输出1
//eregi()  无符号的


$b7 = "asd&ass@ass&adfdf";

$pattern1 = "&";
$pattern2 = "[&@]";
print_r(split($pattern1,$b7));
print_r(split($pattern2,$b7));


echo "<br>";
$b8 = "helloworld";
$pattern3 = "world";
$replacement1 = "persion";
echo ereg_replace($pattern3,$replacement1,$b8);


echo "<br>";
echo sql_regcase("abcdefg");
//输出:[Aa][Bb][Cc][Dd][Ee][Ff][Gg]


//Perl 正则表达式 perl是在支持posix的基础上额外的扩展 \d数字 \D非数字 \s空白 \S非空白 \w字母数学符号下划线 \W非字母数字符号下划线
 
//常用函数array preg_grep ( string pattern, array input )
echo "<br>";
$w1 = array("adad","adad4","asda","1asf3","sdfs");
$fl_array = preg_grep ("/^\D{1,}$/", $w1);//此处强调一点{1,}而不是posix中的{1.}
print_r($fl_array);


echo "<br>";
echo preg_match ("/a/","abc");
//输出1


echo "<br>";
//\b表示单词的边界
if (preg_match ("/\bweb\b/i", "PHP is the web scripting language of choice.")) {
    print "A match was found.";
} else {
    print "A match was not found.";
}


if (preg_match ("/\bweb\b/i", "PHP is the website scripting language of choice.")) {
    print "A match was found.";
} else {
    print "A match was not found.";
}
//尤其是在匹配电子邮箱是常用


echo "<br>";
$pattern5 = "/[\*]+/";
$w3 = "aaa***bbb*ccc";
print_r(preg_split($pattern5,$w3));


echo "<br>";
$pattern6 = "/world/";
$content2 = "girl";
$tre = "hello world";
echo preg_replace($pattern6,$content2,$tre);


//string preg_quote ( string str [, string delimiter] )转义
echo "<br>";
$keywords = "$40 for a g3/400";
$keywords = preg_quote ($keywords, "/");//此处的/若是不加,就不会转义g3/400中的/;
echo $keywords;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值