Question: Example strings:

`myString1 = "/desktop/2512754353/Screenshots/photo_0000.png"`

`myString2 = "/desktop/51232132561/Screenshots/photo_3501.png"`

`myString3 = "/desktop/12321516123/Screenshots/photo_7501.png"`

`myString4 = "/desktop/5234324324/Screenshots/photo_11501.png"`

I had a look around, and couldn't really figure out a proper way to do this. I want to be able to also retrieve the last numbers of my strings after the **photo\_** part, and store them in another variable (string, not int or float). Furthermore, I don't need the number before **/Screenshots**. It would also be nice if it can work for any number length. The **photo\_** will always remain inside the string too.

Answer: 
This calls for a `regex` solution:

```
import re

mystring = "/desktop/2512754353/Screenshots/photo_0000.png"
your_value = re.findall(r'(photo_[0-9]+)', mystring)[0]

print(your_value) # photo_0000

```
Proper way would be to use `pathlib` in conjunction with `re`.

```
import re
from pathlib import Path

pattern = re.compile(r"(?<=photo_)[0-9]*")

pattern.search(Path(myString1).name).group(0)
> '0000'

```