You didn't provide enough information to fully answer the question. Does value always appear before client? Does it always appear after the time and date?
Anyway - this answer, or Quicksilver's answer should work if value does always appear after date and time and before client.
However, you might also just want to search for whatever appears after value=
and before ,
, in which case this should work: https://regex101.com/r/a4d7Bx/1
import re
text = 'isLogIn=true; Max-Age=400; Path=/; Expires=Wed, 25 Sep 2019 17:46:30 GMT, value=qasde% , client=retail'
m = re.search('value=(.+?) ,', text)
if m:
found = m.group(1)
print(found)
Another way to do this by slightly editing your code:
text = 'isLogIn=true; Max-Age=400; Path=/; Expires=Wed, 25 Sep 2019 17:46:30 GMT, value=qasde% , client=retail'
text = text.split('value=', 1)[1]
text = text.split(' , client',1)[0]
print(text)
You asked for the simpler way. Arguably, both of these methods are pretty simple, so I'd opt for the faster one (unless you want the more general solution, in which case use the first option). I timed them using the following code:
import re
import cProfile
text = 'isLogIn=true; Max-Age=400; Path=/; Expires=Wed, 25 Sep 2019 17:46:30 GMT, value=qasde% , client=retail'
def option1(text):
for i in range(10000):
re.search('value=(.+?) ,', text)
def option2(text):
for i in range(10000):
temp = text.split('value=', 1)[1]
temp = temp.split(' , client',1)[0]
cProfile.run("option1(text)")
print("\n\n\n\n\n")
cProfile.run("option2(text)")
And the first option took 0.076 seconds while the second took 0.027 seconds, so the faster option is using split
.