python - Replacing end few characters of list items? -
i'm trying replace lastly few characters of list items unsure how best so..
if illustration list is:
['44 illustration 1/1', '4 illustration here 444/13903', '1 ex exam ple 333/33x'] i want alter x on 3rd one, x shown below:
['44 illustration 1/1', '4 illustration here 444/13903', '1 ex exam ple 333/33x'] another illustration be:
['44 illustration 1/1a', '4 illustration here 444/13903de', '1 ex exam ple 333/33'] changing de de:
['44 illustration 1/1a', '4 illustration here 444/13903de', '1 ex exam ple 333/33'] another illustration be:
['44 illustration 1/1', '4 illustration here 444/13903', '1 ex exam ple 199/1'] changing 199/1 1/1:
['44 illustration 1/1', '4 illustration here 444/13903', '1 ex exam ple 1/1'] i've tried utilize simple .replace(x, y) goes wrong lot middle parts , start.
i have regex created still unsure how it... (\s+) (.*?) (\s+)$
any help appreciated.
use $ match end of string
import re re.sub('de$', 'de', '4 illustration here 444/13903de') python regex string python-2.7 replace
No comments:
Post a Comment