python - get empty list when finding last match -
i want find last word between slashes in url. example, find "nika" in "/gallery/haha/nika/7907/08-2015"
i wrote in python code:
>>> text = '/gallery/haha/nika/7907/08-2015' >>> re.findall(r'/[a-za-z]*/$', text)
but got empty list:
[]
and if delete dollar sign:
>>> re.findall(r'/[a-za-z]*/', text)
the return list not empty '/haha/' missed:
['/gallery/', '/nika/']
anybody knows why?
use lookarounds in
re.findall(r'(?<=/)[a-za-z]*(?=/)', text)
$
means end of string getting empty string.
haha
missing because capturing /
, /
not left haha
. when use lookarounds 0 width assertion , not consume /
, captured.
Comments
Post a Comment