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?
The valid GUID (Globally Unique Identifier) must specify the following conditions: It should be a 128-bit number. It should be 36 characters (32 hexadecimal characters and 4 hyphens) long. It should be displayed in five groups separated by hyphens (-).
The Regex. Replace(String, String, MatchEvaluator, RegexOptions) method is useful for replacing a regular expression match if any of the following conditions is true: If the replacement string cannot readily be specified by a regular expression replacement pattern.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With