Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
PHP:我有这个字符串:1_1234567890, 2_1234567890, 3_1234567890 ...我需要一个正则表达式来查找是否有“2_”,如果是肯定的,删除 2_ 和后面的字符直到下一个逗号,在这种情况下删除“2_123456789” . 所以我的输出,一定是:1_1234567890, 3_1234567890。
$string = preg_replace('|(2_.+?, ?)|', '', $string);
使用 PHP:
$result = preg_replace('~\b2_[^,]*(?:,\h*|\h*$)~', '', $str);