我可以用普通的字符串函数做到这一点,但万一我不知道这件事是否可以在正则表达式的方式完成。从“/”之间的字符串中提取文本和数字
$list = array("animal","human","bird");
$input1 = "Hello, I am an /animal/1451/ and /bird/4455";
$input2 = "Hello, I am an /human/4461451";
$input3 = "Hello, I am an /alien/4461451";
$output1 = ["type"=>"animal","number"=>1451],["type"=>"bird","number"=>4455]];
$output2 = [["type"=>"human","number"=>4461451]];
$output3 = [[]];
function doStuff($input,$list){
$input = explode(" ",$input);
foreach($input as $in){
foreach($list as $l){
if(strpos($in,"/".$l) === 0){
//do substr to get number and store in array
}
}
}
}
'为我写代码'问题?或者你已经尝试过一些东西? –
即时更新等待我试过 –
我很困惑的标签,它应该是PHP? JavaScript的? – BrunoLM