Reputation: 239
From this list
List = ['/asd/dfg/ert.py','/wer/cde/xcv.img']
Got this
List = ['ert.py','xcv.img']
Upvotes: 1
Views: 61
Reputation: 711
$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);
Upvotes: -1
Reputation: 353079
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.
Upvotes: 6