I'm having a bad moment trying to make a regex that can find line similar to this in files :
Bearer 89abddfb-2cff-4fda-83e6-13221f0c3d4f
It should have Bearer at the begining followed by space, and the token after is the same format : [hexadecimal, 8 char]-[hexadecimal, 4 char]-[hexadecimal, 4 char]-[hexadecimal, 4 char]-[hexadecimal, 12 char]
Any help would be very appreciated
PS: Maybe just the regex of the token format will be enough to find the token without the Bearer not sure
RegEx tested with PowerShell
'Bearer\s[\d|a-f]{8}-[\d|a-f]{4}-[\d|a-f]{4}-[\d|a-f]{4}-[\d|a-f]{12}'
Edit: shorter version
'Bearer\s[\d|a-f]{8}-([\d|a-f]{4}-){3}[\d|a-f]{12}'
import re
data = "Bearer 89abddfb-2cff-4fda-83e6-13221f0c3d4f"
print(re.findall(r'(Bearer )([a-f\d]{8})-([a-f\d]{4})-([a-f\d]{4})-([a-f\d]{4})-([a-f\d]{12})', data))
The explanation on Regex101 here.
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