string - Get specific parts of a file path in Python -
i have path string
'/path/eds/vs/accescontrol.dat/d=12520/file1.dat'
q1: how can accescontrol.dat
path.
q2: how can /path/eds/vs/accescontrol.dat
path.
import re url = '/path/eds/vs/accescontrol.dat/d=12520/file1.dat' match = re.search('^(.+/([^/]+\.dat))[^$]', url) print match.group(1) # outputs /path/eds/vs/accescontrol.dat print match.group(2) # outputs accescontrol.dat
i edited work in python2 , reply both questions (the before regex reply above answers first of two)
python string python-2.7 path
No comments:
Post a Comment