I want to filter strings in a list based on a regular expression. I tried defining as variable ${TagValue} but it gives null value or an empty list:
Bascially i want to list down those instances that have Environment tag is equal to the "Tag Value":
Here's my code:
TagValue = ['DEV', 'DEVDR', 'QA','TEST', 'SND', 'STG', 'sit', 'sandbox', 'Development', 'NonProd', 'NON-PROD']
instance_list = []
Instances = ec2_resource.instances.all()
for each in Instances:
instance_list.append(each.id) # count total # of instances including all env tags
for i in instance_list:
ins_res = ec2_resource.Instance(i)
ins_tag = ins_res.tags
ins_state = ins_res.state
if ins_state['Name']=='running':
for item in ins_tag:
if item['Key'] == 'Environment':
val = item['Value']
pattern = re.compile(r'\b${tag_value}\w*', re.IGNORECASE)
print(re.findall(pattern,val))
Output is:
[]
[]
[]
.....
$in the regexp matches the end of the string. It doesn't make sense to have{tag_value}after that.$before{expression}.TagValue? See stackoverflow.com/questions/33406313/…