Image label from regular expression

I am trying to extract the label from the path names as suggested by Jeremy. But I am not getting the label properly.

Instead of just ‘cats’, it is coming something like ‘cats.12’.
How should I solve this?

try this regex:

r'(.+)\.\d+\.jpg$'

there are some great regex tutorials online.

What this says is:
(.+) what’s in the parenthesis are the “capture group”; what you care about
. dot means any character, + means one or more of them

\. means a regular dot
\d+ means any digit and the plus means one or more of them
.jpg means .jpg
$ means end of line or in this case end of string

try the regex and if it doesn’t work, debug it, it’s fun AND a necessary skill for this type of learning.