查找字符串中任何数字首次出现的位置 [英] Find the position of the first occurrence of any number in string
本文介绍了查找字符串中任何数字首次出现的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我找到在字符串中任何数字首次出现的位置的算法吗?
Can someone help me with algorithm for finding the position of the first occurrence of any number in a string?
我在网上找到的代码无法正常工作:
The code I found on the web does not work:
function my_offset($text){
preg_match('/^[^\-]*-\D*/', $text, $m);
return strlen($m[0]);
}
echo my_offset('[HorribleSubs] Bleach - 311 [720p].mkv');
推荐答案
function my_ofset($text){
preg_match('/^\D*(?=\d)/', $text, $m);
return isset($m[0]) ? strlen($m[0]) : false;
}
应该适用。原始代码要求在第一个数字之前使用-
,也许是问题所在?
should work for this. The original code required a -
to come before the first number, perhaps that was the problem?
这篇关于查找字符串中任何数字首次出现的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文