I have been creating a few regex patterns to search a file. I basically need to search each line of a text file as a string of values. The issue I am having is that the regexs I have created work when used against a list of of values; however, I can not use the same regex when I search a string using the same regex. I'm not sure what I am missing. My test code is below. The regex works against the list_primary, but when I change it to string2, the regex does not find the date value I'm looking for.
import re
list_primary = ["Wi-Fi", "goat", "Access Point", "(683A1E320680)", "detected", "Access Point detected", "2/5/2021", "10:44:45 PM", "Local", "41.289227", "-72.958748"]
string1 = "Wi-Fi Access Point (683A1E320680) detected puppy Access Point detected 2/5/2021 10:44:45 PM Local 41.289227 -72.958748"
#Lattitude = re.findall("[0-9][0-9][.][0-9][0-9][0-9][0-9][0-9][0-9]")
#Longitude = re.findall("[-][0-9][0-9][.][0-9][0-9][0-9][0-9][0-9][0-9]")
string2 = string1.split('"')
# print(string2)
list1 = []
for item in string2:
data_dict = {}
date_field = re.search(r"(\d{1})[/.-](\d{1})[/.-](\d{4})$",item)
print(date_field)
if date_field is not None:
date = date_field.group()
else:
date = None
for item in string2:means you iterate over each char instring1. You need tore.searchagainststring1rx = re.compile(r"(?<!\d)\d{1,2}[/.-]\d{1,2}[/.-]\d{4}(?!\d)")and thenprint(list(filter(rx.search, list_primary)))