I got the value | (special pipe symbol) in regex, Python. It corresponds to either 1st or 2nd.
ex: a|b Matches either a or b.
My question is: What if I want to combine a with case-sensitive and b with case-insensitive in the above example?
Example:
s = "Welcome to PuNe, Maharashtra" result1 = re.search("punnee|MaHaRaShTrA",s) result2 = re.search("pune|maharashtra",s) result3 = re.search("PuNe|MaHaRaShTrA",s) result4 = re.search("P|MaHaRaShTrA",s)
I want to search for Pune as I wrote in the above statement, PuNe . But I have to look for Maharashtra, ignoring the case. How can I search for 1 word case sensitive and another case insensitive? Thus, result1 , result2 , result3 , result4 will give the value not null .
I tried :
result1 = re.search("pune|MaHaRaShTrA",s1, re.IGNORECASE)
But it ignores cases for both words.
How can I limit 1 word to case sensitive and another to case insensitive?
source share