I am trying to write regular expression in python. Let’s say that I have a string
string = "alpha=23; beta=34; gamma=43"
I want to read this string and store the values of alpha, beta and gamma in a database. How can I write a regex that would do that.
My guess is that i have to look for regex that checks for words followed by = sign. I wrote this:
matchObj = re.search( r'\w+(?==)', string, re.I)
This outputs alpha and stops?
- Is this correct?
- How can i read all the values?
1
Yes it is correct, search stops after the first match.
2
try
findallinstead ofsearchIt returns a list.
If you want to use split: