'''
python 使用正則表達式, 也可以先 編譯一個正則, 然後,用這個正則 去 match ,search , findall
'''
text = "text my * IOD soela MYVso its Tye We tokyo hot "
pattern = r'my'
regex = re.compile(pattern, flags=re.IGNORECASE)
regex.search(text)
print(regex.search(text))
regex.search(text).group()
regex.findall(text)
這個平時我都是直接用 字符串。比如:
text = "text my100 * IOD soela MYVso its Tye We tokyo hot "
pattern = r'my\d+'
regex = re.compile(pattern)
regex.findall(text)
re.findall(pattern, text)