1、选中被逗号(或其他符号)分割的字符串当中的某一个值
69,23,69,88,695,69,69,6,765769fd969690,3242,969,69
实例,选中以上字符串所有出现的69部分
(\b69\b[,]?)|([,]?\b69\b)
javascript
var val = "69"; var exp = new RegExp("(\\b"+val+"\\b[,]?)|([,]?\\b"+val+"\\b)","g");
php
$matches = array(); $search = ‘69,23,69,88,695,69,69,6,765769fd969690,3242,969,69‘; $target = ‘69‘; $pattern = ‘/(\b‘.$target.‘\b[,]?)|([,]?\b‘.$target.‘\b)/‘; preg_match_all ($pattern, $search, $matches);
时间: 2024-11-07 19:35:59