import re print(re.search(r"[Pp]ython", "Python")) print(re.search(r"[a-z]way", "The end of the highway")) print(re.search(r"cloud[a-zA-Z0-9]", "cloudy")) # put ^ before a character class to search for anything but the given character class print(re.search(r"[^a-zA-Z]", "This is a sentence with spaces.")) # | as OR operator print(re.search(r"cat|dog", "I like dogs.")) print(re.findall(r"cat|dog", "I like both cats and dogs."))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter