网站首页 laravel框架
正则常见用格式
发布时间:1970-01-01 00:00查看次数:3271
<?php
////邮箱正则
1. email(验证,采集 , $str , $html ,' /???/' )
$email = '48855784@qq.com,qqqqq,qqqqddd,dddd@vv.cn,xinlang@goodle.com.cn';
$guize = '/[a-zA-Z0-9]{1,20}\@[a-z]+\.[a-z\.]+/';
//正则方式拆分成3部分 @前 @到.中间 .后边的
//@前的 字符+大写字符 +0-9数字 长度0=21
//@后边字符a-z
//.后边a-z \. 因为A-Z是不包含点的所以这里把点包含进去
preg_match_all($guize,$email,$cc);
print_r($cc);
//4. 把网页的链接换成#,空连接
//6. 采集163新闻标题和内容,并过滤html标签(单行模式,贪婪模式)
2. 验证用户输入的时间是否为 yyyy-mm-dd hh:ii:ss
$str ='1982-5-10,1982-10-10 14:45:52';
//$guize = '/[0-9\-]+\s+[0-9\:]+\:[0-9]+\:[0-9]+/';
$guize = '/[0-9\-]+\s+[0-9\:]+/';
//这个拆分成3部分 空格前 与空格后 空格前0-9以及\-线
//然后匹配空格 长度
//在匹配空格后边0-9 \:号
preg_match($guize,$str,$cc);
print_r($cc);
3. 清除一个页面上的所有script代码,和onclick,onready等事件代码
$str=<<<text
<script>
var text = '';
var title = '';
window.onload = function () {
text = document.getElementById('caidan');
title = document.getElementById('title');
document.getElementById('weixin').onclick = function () {
var wenben = title.value;
var yijibotton = '{"button": [{"type": "click","name": "'+wenben+'","key": "V1001_TODAY_MUSIC"}]}';
text.innerHTML = yijibotton;
}
document.getElementById('weixin2').onclick = function () {
var wenben = document.getElementById('erjiCaiDan');
wenben = wenben.value;
var dianji =document.getElementById('erjiDianJi');
dianji = dianji.value;
var erJiBotton = '{"name": "'+wenben+'","sub_button": [{"type": "view","name": "'+dianji+'","url": "http://www.soso.com/"}]}';
text.innerHTML= erJiBotton;
}
}
</script>
</html>
text;
echo $str;
$guize = '/\B\<script\>\B.+\B\<\/script\>\B/s';
$guize = '/\b\<script\>\b.+\b\<\/script\>\b/s';
$a =preg_replace($guize,'',$str);
preg_match_all($guize,$str,$cc);
var_dump($cc);
5. 正则分析文件后缀
$str = '1.jpg,2.rar,5.zip,9.9.jpg';
$guize = '/\.{1}[a-z]{0,3}/';
preg_match_all($guize,$str,$cc);
print_r($cc);
6. 采集163新闻标题和内容,并过滤html标签(单行模式,贪婪模式)
关键字词:正则常见用格式