Let’s say we want to match every single rain variation ..
“Isolated rain over coastal area” is rain.
“Scattered rain over inland area” is rain.
“Rain” is rain
but not “No rain” .. is Fair weather ..
#!/usr/bin/python import re z = 1 y = 2 x = 3 if (z == 1) & (x == 3) & (y == 2): print "match" else: print "not match" norain = 'No rain' rain = 'Rain' rainfall = 'isolated rain interne' zrain =re.compile ('(?<!No\s)[Rr]ain') m_rain = zrain.search (rainfall) m2_rain = zrain.search (rain) m1_rain = zrain.search (norain) if m_rain : print "got rainfall" if m2_rain : print "got me : Rain" if m1_rain: print "no rain also defined as rain" else : print "No rain is :not raining OK!"
result would be something like follows :
the above function can be simplified a but further with the following :
hmm. if putting into a file and read from there would be much more better.
to make it read from a text file and behave exactly as above.
then create text file with the following content.