I am writing a Python script that reads through a file line by line and searches for any line of the syntax var_name = value. If one is found, it sets the variables name and value to the values from that line. This is what I have so far:
import re
for i in file:
name = ""
value = ""
if re.match('^[A-Za-z0-9]*[\\s]?\=[\\s]?.*$', x):
#operations to set variables needed here...
#then use new variables
The problem is I learned regex in a Linux environment, and it seems that Python has a bunch of different rules and functions pertaining to it. I'm pretty new to Python as is, so it's been rather confusing trying to figure this out. I've been searching around and found a reasonable amount on checking for a regex match, but nothing on pulling out values that match once said match is found. I tried something like this:
name = re.search(' (?=[\\s]?\=.*)', x)
value = re.search(' (?<=[A-Za-z0-9]*[\\s]?\=[\\s]?) ', x)
...based on what I found here, but it doesn't work, and I'm not sure what part of the operation is incorrect. If anyone has any ideas they could share, it would be greatly appreciated. Thanks!