随笔分类 -  正则表达式

摘要:php :xxxabc';$matches = array();if(preg_match('/.*/i', $str, $matches)){ echo $matches[0];}?>//输出xxx?>js :jquery:var username=new RegExp(/^[a-zA-Z]\w{2,14}$/);if(!mobile.test(username)){ con = "请输入字母开头的3-15个字符";alert(con); }只能输入数字:"^[0-9]*$"。只能输入n位的数字:"^\d{ 阅读全文
posted @ 2013-12-30 15:18 jami918 阅读(242) 评论(0) 推荐(0)
摘要:匹配ip地址:((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}2[0-4]\d|25[0-5]|[01]?\d\d?后向引用:(\w+)\s?\\1注意:数字1前面有两个\零宽断言:1:(?exp) 如:\w+(?=ing)查找字符串i'm singing 匹配sing2:(?<=exp) 如:(?<=re)\w+查找字符串i'm reading 匹配ading3:综合运用如:/(?<=<((\w)+)>).*(?=<\/\\1>)/ 匹配html标签如<b>.*</b>负向零宽断言:1: 阅读全文
posted @ 2013-05-03 17:20 jami918 阅读(142) 评论(0) 推荐(0)