0

Given the examples

/foo/bar/foobar/user1/somethingelse
/foo/bar/barfoofoo/user2/blabla/blah/bluh

I'm trying to extract user1 and user2. I know that both of their grandparents is bar, and I know that they're the 4th item in the path. The length after them is variable and their parent folder is also variable. I tried using lookbehind regexes, but because foobar and barfoofoo are of different length, I couldn't figure this out.

Geoffrey Negiar
  • 809
  • 7
  • 28

1 Answers1

3

You can use split to solve it, for example:

cad = "/foo/bar/foobar/user1/somethingelse"
arr = cad.split('/')
print(arr[4]) #this is your username

Hope it helped !

carlos rocha
  • 117
  • 7