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.
这是我的字符串:left_image_12。
left_image_12
我想省略_12,只显示left_image。我无法弄清楚这一点。
_12
left_image
您可以使用捕获组来做到这一点:
^(.*?)_\d+$
$1(或 \1,取决于您的语言)将包含名称,但最后没有数字。
试试这个:
preg_match($string, "/^([A-Za-z_]+)_\d+$/", $match); $output = $match[1];