I have a s3 object in the following format.
https://s3-{region}.amazonaws.com/{bucket}/{environment}/{keyname}
I need a regex which can fetch me the individual variables from a s3 link. Currently I have the following regex.
r"https\:\/\/s3\-(\w+)\.amazonaws\.com\/(\w+)\/(\w+)\/(\w+)$"
But it returns None.
You could go for:
https?://s3-
(?P<region>[^.]+).amazonaws.com/
(?P<bucket>[^/]+)/
(?P<environment>[^/]+)/
(?P<keyname>.*)
Python this would be:
import re
rx = re.compile(r'''
https?://s3-
(?P<region>[^.]+).amazonaws.com/
(?P<bucket>[^/]+)/
(?P<environment>[^/]+)/
(?P<keyname>.*)''', re.VERBOSE)
links = rx.findall(your_string_here)