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) 

see demo


$ means end of string getting empty string.

haha missing because capturing / , / not left haha. when use lookarounds 0 width assertion , not consume / , captured.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -