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_abc.jpg -> abc.jpg 01_abc.jpg -> abc.jpg 100_abc.jpg -> abc.jpg 100_12abc.jpg -> 12abc.jpg 12abc.jpg -> 12abc.jpg
提前致谢。我真的不擅长正则表达式。
你真的需要正则表达式吗?
$pos = strpos($string, '_'); if($pos !== false) $string = substr($string, $pos + 1);
...或者:
$string = preg_replace('/^\d+_/', '', $string);
(^匹配字符串的开头并d+匹配数字)
^
d+