I am mainly using this in ansible but I figured its similar in python. So I have a list of strings which I need to extract words from it that start with a certain pattern. For example if I have the following:
list1: ['water_3gallons_6/20/22 490832', 'applejuice_1liter_6/18/22 490833', 'soda_2liters_6/22/22 490834', 'water_1gal_today 490835']
# and lets say I only want to pull the words that start with water (ignoring the 490832 part)
# meaning it should return this list: ['water_3gallons_6/20/22','water_1gal_today']
# I was using the following 2 codes and it was returning an empty list
- name: "Create list of words that start with water from list1 variable"
set_fact:
start_with_water: "{{ list1 |regex_findall('^water') }}" # RETURNED EMPTY LIST
- name: "Create list of words that start with water from list1 variable"
set_fact:
start_with_water: "{{ list1 |regex_findall('\\Awater') }}" # RETURNED EMPTY LIST TOO