String has multiple data and need to find the match and get the value of comma separated aws regions
data = '''
appname=ivr
age=2years
region='us-east-1a,us-east-2a,us-east-1c'
'''
Would like to get the value for region in out put as 'us-east-1a,us-east-2a,us-east-1c'
tried using this regex but it works only for one value without comma
'(af|il|ap|ca|eu|me|sa|us|cn|us-gov|us-iso|us-isob)-(central|north|. (north(?:east|west))|south|south(?:east|west)|east|west)-d{1}'
2
Answers
You could just add an optional comma on the end of your regex and then make that a repeating group:
Output:
A different approach is to use the
csv
library to parse:Output:
Notes
data.strip().splitlines()
cleans up the data and split it into linescsv.reader
, specifying the equal sign as the fields delimiter.dict()
to turn them into a dictionary.