。例如,在“/gallery/haha/nika/7907/08-2015”中找到“nika”
I wrote this in my python code:

>>> text = '/gallery/haha/nika/7907/08-2015'
>>> re.findall(r'/[a-zA-Z]*/$', text)

but I got an empty list:
[]

And if I delete that dollar sign:
>>> re.findall(r'/[a-zA-Z]*/', text)

The return list is not empty but '/haha/' is missed:
['/gallery/', '/nika/']

有人知道为什么吗?

最佳答案

Use lookarounds as in

re.findall(r'(?<=/)[a-zA-Z]*(?=/)', text)

See demo
$表示字符串结束,因此您将得到空字符串。
。。

07-24 09:16