
正则表达式
大洋PHP
用技术逆袭生活。
展开
-
分割同个字符不同位置
情况: 字符串:Industrial & Scientific,Professional Medical Supplies,Durable Medical Equipment,Braces, Splints & Supports,Back, Neck & Shoulder Supports 最终表达式为: $strNew = preg_replace('/(,)(\S)/','->${2}',$str); 这个表达式将会把第一个字符也替换: $strNew = pr原创 2022-02-17 15:36:18 · 138 阅读 · 0 评论 -
正则表达式 汇总记录
1、任务字符,除\n之外的 '/.*/'原创 2020-06-24 13:45:33 · 156 阅读 · 0 评论 -
php 删除之间的内容
$pattern = "/<.*>/"; $result = preg_replace($pattern,"",$str); $isHasCompatibilityYes = preg_replace('/(<span\s\S>)\s\S(</span>)/','',$isHasCompatibilityYes); #span原创 2018-08-02 17:08:45 · 600 阅读 · 0 评论 -
正则匹配,只保留中文、英文、数字
function match_chinese($chars,$encoding='utf8') { $pattern =($encoding=='utf8')?'/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u':'/[\x80-\xFF]/'; preg_match_all($pattern,$chars,$result); ...原创 2019-03-12 17:30:26 · 9110 阅读 · 0 评论 -
php去除换行符的方法
本来在unix世界换行就用/n来代替,但是windows为了体现他的不同,就用/r/n,更有意思的是在mac中用/r。因此unix系列用 /n,windows系列用 /r/n,mac用 /r $content=str_replace("\n","",$content); echo $content; str_replace("\r\n","",$str); $content=preg_r...原创 2019-03-12 17:53:58 · 2563 阅读 · 0 评论 -
数字处理
1、匹配1到100,一位小数点 '/^[1-9]\d?(\.\d?)?$/' if (!preg_match('/^[1-9]\d?(\.\d?)?$/',$num)){ throw new RuntimeException('固定比例,只能是1-100之间且一位小数位的值',500); } ...原创 2019-08-22 12:54:47 · 126 阅读 · 0 评论