What would be the regular expression for such data
/home//Desktop/3A5F.py
path/sth/R67G.py
a/b/c/d/t/6UY7.py
i would like to get these
3A5F.py
R67G.py
6UY7.py
What would be the regular expression for such data
/home//Desktop/3A5F.py
path/sth/R67G.py
a/b/c/d/t/6UY7.py
i would like to get these
3A5F.py
R67G.py
6UY7.py
It is a simple split
, no regex needed:
>>> "/home//Desktop/3A5F.py".split("/")[-1]
'3A5F.py'
As an alternative, you can get same result without regexps:
lines = ['/home//Desktop/3A5F.py', 'path/sth/R67G.py', 'a/b/c/d/t/6UY7.py']
result = [l.split('/')[-1] for l in lines]
print result
# ['3A5F.py', 'R67G.py', '6UY7.py']
use : [^\/]*\.py$
But this is a bad question. You need to show what you have try. Whe are not here to do your work for you.
You can use this.
pattern = ".*/(.*$)"
mystring = "/home//Desktop/3A5F.py"
re.findall(pattern, mystring)
You can also use os.path.split(mystring)