Given 2 different regex patterns, i want to find all occurrences of those 2 patters. If only pattern 1 matches then return that, if only pattern 2 matches then return that and if pattern 1 and pattern 2 matches then return both of them. So how do i run multiple(in this case 2 regex) in one statement?
Given input string :
"https://test.com/change-password?secret=12345;email=test@gmail.com;previous_password=hello;new=1"
I want to get the value of email and secret only. So i want the output as ['12345', 'test@gmail.com']
import re
print(re.search(r"(?<=secret=)[^;]+", s).group())
print(re.search(r"(?<=email=)[^;]+", s).group())
I am able to get the expected output by running the regex multiple times. How do i achieve it within a single statement? I dont want to run re.search 2 times. Can i achieve this within one search statement?