I have a string that looks something like this -
text = 'during the day, the color of the sky is blue. at sunset, the color of the sky is orange.'
I need to extract the words after a particular sub-string, in this case, 'sky is'. That is, I want a list that gives me this -
['blue', 'orange']
I have tried the following -
p1 =re.compile(r"is (.+?) ",re.I)
re.findall(p1,text)
But this gives the output only as
['blue']
If, however, my text is
text = 'during the day, the color of the sky is blue at sunset, the color of the sky is orange or yellow.'
and I run
p1 = re.compile(r"is (.+?) ",re.I)
re.findall(p1,text)
I get the output as -
['blue', 'orange']
Please help! I am new to regular expressions and I am stuck!
re.compile(r"is (.+?)( |\.)", re.I)sky is orange.ends with a dot. If you want to match either a space or dot\bis (.+?)[ .]or only a single word\bis (\w+)[ .]re.findall(r'(?i)\bsky\s+is\s+(\w+)', text)