从这个列表
List = ['/asd/dfg/ert.py','/wer/cde/xcv.img']
明白啦
List = ['ert.py','xcv.img']
从这个列表
List = ['/asd/dfg/ert.py','/wer/cde/xcv.img']
明白啦
List = ['ert.py','xcv.img']
There's a low-level split
-based approach:
>>> a = ['/asd/dfg/ert.py','/wer/cde/xcv.img']
>>> b = [elem.split("/")[-1] for elem in a]
>>> b
['ert.py', 'xcv.img']
Or a higher-level, more descriptive approach, which is probably more robust:
>>> import os
>>> b = [os.path.basename(filename) for filename in a]
>>> b
['ert.py', 'xcv.img']
Of course this assumes that I've guessed right about what you wanted; your example is somewhat underspecified.
$List = array('/asd/dfg/ert.py','/wer/cde/xcv.img');
$pattern = "#/.*/#";
foreach ($List AS $key => $str)
$List[$key] = preg_replace($pattern, '', $str);
print_r($List);