How to get particular text using regex
Question:
import re
cookie_jar = "<RequestsCookieJar[<Cookie JSESSIONID=EA47DC319D1977863BBEC8E4AFB408DF.node60877 for tah.appiancloud.com/suite>, <Cookie SCS_REMEMBER_ME_COOKIE=jA0EAwMC3Bc7KwH4uMsB0kUBOqr2TjQT9LIqoOmfUaCFiPtA7JqG9A8lihrCrKyg6yK2EYEqkHvCfEQwVTcKP9CYYFtwGkG7rGDH8UY6IPhJPKa2tsg for tah.appiancloud.com/suite>, <Cookie SPRING_SECURITY_REMEMBER_ME_COOKIE=TExNTXNyJTJGQjBqVTN6OWFZQ0xSV1RuOVhVcEhtczdhNlFXd0swJTJCd2VGOEElM0Q6TGRQU0MlMkZHRVgyYVhKZldBTVQwQWdQVTMzWTA5VENvaUY0NWxBdlhiYSUyRlklM0Q for tah.appiancloud.com/suite>, <Cookie __appianCsrfToken=d815e694-2118-4b3e-92c7-6b750b9557d2 for tah.appiancloud.com/suite>, <Cookie __appianMultipartCsrfToken=f80ce677-9adf-409e-a755-89105f51437e for tah.appiancloud.com/suite>]>
"
print(re.findall("__appianCsrfTokens*=s*([^;]+);?",cookie_jar))
Required output: d815e694-2118-4b3e-92c7-6b750b9557d2
Is there any solution to get __appianCsrfToken only the value
Answers:
regex description https://regex101.com/r/b42RMQ/1
import re
cookie_jar = "<RequestsCookieJar[<Cookie JSESSIONID=EA47DC319D1977863BBEC8E4AFB408DF.node60877 for tah.appiancloud.com/suite>, <Cookie SCS_REMEMBER_ME_COOKIE=jA0EAwMC3Bc7KwH4uMsB0kUBOqr2TjQT9LIqoOmfUaCFiPtA7JqG9A8lihrCrKyg6yK2EYEqkHvCfEQwVTcKP9CYYFtwGkG7rGDH8UY6IPhJPKa2tsg for tah.appiancloud.com/suite>, <Cookie SPRING_SECURITY_REMEMBER_ME_COOKIE=TExNTXNyJTJGQjBqVTN6OWFZQ0xSV1RuOVhVcEhtczdhNlFXd0swJTJCd2VGOEElM0Q6TGRQU0MlMkZHRVgyYVhKZldBTVQwQWdQVTMzWTA5VENvaUY0NWxBdlhiYSUyRlklM0Q for tah.appiancloud.com/suite>, <Cookie __appianCsrfToken=d815e694-2118-4b3e-92c7-6b750b9557d2 for tah.appiancloud.com/suite>, <Cookie __appianMultipartCsrfToken=f80ce677-9adf-409e-a755-89105f51437e for tah.appiancloud.com/suite>]>"
print(re.findall(r"__appianCsrfTokens*=([^s]+)",cookie_jar)) #['d815e694-2118-4b3e-92c7-6b750b9557d2']
You need to replace your regex by __appianCsrfTokens*=s*([^s]+)s
So your final code is :
import re
cookie_jar = "<RequestsCookieJar[<Cookie JSESSIONID=EA47DC319D1977863BBEC8E4AFB408DF.node60877 for tah.appiancloud.com/suite>, <Cookie SCS_REMEMBER_ME_COOKIE=jA0EAwMC3Bc7KwH4uMsB0kUBOqr2TjQT9LIqoOmfUaCFiPtA7JqG9A8lihrCrKyg6yK2EYEqkHvCfEQwVTcKP9CYYFtwGkG7rGDH8UY6IPhJPKa2tsg for tah.appiancloud.com/suite>, <Cookie SPRING_SECURITY_REMEMBER_ME_COOKIE=TExNTXNyJTJGQjBqVTN6OWFZQ0xSV1RuOVhVcEhtczdhNlFXd0swJTJCd2VGOEElM0Q6TGRQU0MlMkZHRVgyYVhKZldBTVQwQWdQVTMzWTA5VENvaUY0NWxBdlhiYSUyRlklM0Q for tah.appiancloud.com/suite>, <Cookie __appianCsrfToken=d815e694-2118-4b3e-92c7-6b750b9557d2 for tah.appiancloud.com/suite>, <Cookie __appianMultipartCsrfToken=f80ce677-9adf-409e-a755-89105f51437e for tah.appiancloud.com/suite>]>"
result = re.findall("__appianCsrfTokens*=s*([^s]+)s",cookie_jar)
if result:
print(result[0])
Result :
d815e694-2118-4b3e-92c7-6b750b9557d2
import re
cookie_jar = "<RequestsCookieJar[<Cookie JSESSIONID=EA47DC319D1977863BBEC8E4AFB408DF.node60877 for tah.appiancloud.com/suite>, <Cookie SCS_REMEMBER_ME_COOKIE=jA0EAwMC3Bc7KwH4uMsB0kUBOqr2TjQT9LIqoOmfUaCFiPtA7JqG9A8lihrCrKyg6yK2EYEqkHvCfEQwVTcKP9CYYFtwGkG7rGDH8UY6IPhJPKa2tsg for tah.appiancloud.com/suite>, <Cookie SPRING_SECURITY_REMEMBER_ME_COOKIE=TExNTXNyJTJGQjBqVTN6OWFZQ0xSV1RuOVhVcEhtczdhNlFXd0swJTJCd2VGOEElM0Q6TGRQU0MlMkZHRVgyYVhKZldBTVQwQWdQVTMzWTA5VENvaUY0NWxBdlhiYSUyRlklM0Q for tah.appiancloud.com/suite>, <Cookie __appianCsrfToken=d815e694-2118-4b3e-92c7-6b750b9557d2 for tah.appiancloud.com/suite>, <Cookie __appianMultipartCsrfToken=f80ce677-9adf-409e-a755-89105f51437e for tah.appiancloud.com/suite>]>
"
print(re.findall("__appianCsrfTokens*=s*([^;]+);?",cookie_jar))
Required output: d815e694-2118-4b3e-92c7-6b750b9557d2
Is there any solution to get __appianCsrfToken only the value
regex description https://regex101.com/r/b42RMQ/1
import re
cookie_jar = "<RequestsCookieJar[<Cookie JSESSIONID=EA47DC319D1977863BBEC8E4AFB408DF.node60877 for tah.appiancloud.com/suite>, <Cookie SCS_REMEMBER_ME_COOKIE=jA0EAwMC3Bc7KwH4uMsB0kUBOqr2TjQT9LIqoOmfUaCFiPtA7JqG9A8lihrCrKyg6yK2EYEqkHvCfEQwVTcKP9CYYFtwGkG7rGDH8UY6IPhJPKa2tsg for tah.appiancloud.com/suite>, <Cookie SPRING_SECURITY_REMEMBER_ME_COOKIE=TExNTXNyJTJGQjBqVTN6OWFZQ0xSV1RuOVhVcEhtczdhNlFXd0swJTJCd2VGOEElM0Q6TGRQU0MlMkZHRVgyYVhKZldBTVQwQWdQVTMzWTA5VENvaUY0NWxBdlhiYSUyRlklM0Q for tah.appiancloud.com/suite>, <Cookie __appianCsrfToken=d815e694-2118-4b3e-92c7-6b750b9557d2 for tah.appiancloud.com/suite>, <Cookie __appianMultipartCsrfToken=f80ce677-9adf-409e-a755-89105f51437e for tah.appiancloud.com/suite>]>"
print(re.findall(r"__appianCsrfTokens*=([^s]+)",cookie_jar)) #['d815e694-2118-4b3e-92c7-6b750b9557d2']
You need to replace your regex by __appianCsrfTokens*=s*([^s]+)s
So your final code is :
import re
cookie_jar = "<RequestsCookieJar[<Cookie JSESSIONID=EA47DC319D1977863BBEC8E4AFB408DF.node60877 for tah.appiancloud.com/suite>, <Cookie SCS_REMEMBER_ME_COOKIE=jA0EAwMC3Bc7KwH4uMsB0kUBOqr2TjQT9LIqoOmfUaCFiPtA7JqG9A8lihrCrKyg6yK2EYEqkHvCfEQwVTcKP9CYYFtwGkG7rGDH8UY6IPhJPKa2tsg for tah.appiancloud.com/suite>, <Cookie SPRING_SECURITY_REMEMBER_ME_COOKIE=TExNTXNyJTJGQjBqVTN6OWFZQ0xSV1RuOVhVcEhtczdhNlFXd0swJTJCd2VGOEElM0Q6TGRQU0MlMkZHRVgyYVhKZldBTVQwQWdQVTMzWTA5VENvaUY0NWxBdlhiYSUyRlklM0Q for tah.appiancloud.com/suite>, <Cookie __appianCsrfToken=d815e694-2118-4b3e-92c7-6b750b9557d2 for tah.appiancloud.com/suite>, <Cookie __appianMultipartCsrfToken=f80ce677-9adf-409e-a755-89105f51437e for tah.appiancloud.com/suite>]>"
result = re.findall("__appianCsrfTokens*=s*([^s]+)s",cookie_jar)
if result:
print(result[0])
Result :
d815e694-2118-4b3e-92c7-6b750b9557d2