Run ❯
Get your
own Python
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
import re text = "The rain in Spain falls mainly on the plain" #Find and return words that contains the phrase "ain": pattern = """ [A-Za-z]* #starts with any letter ain+ #contains 'ain' [a-z]* #followed by any small letter """ print(re.findall(pattern, text, re.VERBOSE)) #The example would return nothing without the re.VERBOSE flag print(re.findall(pattern, text)) #Same result with the shorthand re.X flag: print(re.findall(pattern, text, re.X))
['rain', 'Spain', 'mainly', 'plain']
[]
['rain', 'Spain', 'mainly', 'plain']