16

Let's say I have this string:

str = 'something-rows-1973912739821738172-25892e17-80f6-415f-9c65-7395632f0223'

I need to remove GUID part:

25892e17-80f6-415f-9c65-7395632f0223

This is what I've so far but it isn't working:

c = re.compile('[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}\Z', re.I)
res = c.match(str)
print(res)

Can anyone please help?

90abyss
  • 7,037
  • 19
  • 63
  • 94

1 Answers1

28

From this answer, you need this:

[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}

Working example: https://regex101.com/r/6pA9Rk/1

Community
  • 1
  • 1
ketan vijayvargiya
  • 5,409
  • 1
  • 21
  • 34
  • To be clear, this answer is the one which **doesn't** match NIL UUID, `00000000-0000-0000-0000-000000000000`. Of course, the answer referenced also includes a regex which will match NIL and non-NIL. – Tyler Montney Aug 23 '23 at 19:52