Pythonで学ぶ正規表現
Maria Eugenia Inzaugarat
Data Scientist
REGular EXpression(regex):
通常の文字と特殊メタ文字の組み合わせからなる文字列で、テキスト内のパターンや位置を表す

REGular EXpression(regex):
通常の文字と特殊メタ文字の組み合わせからなる文字列で、テキスト内のパターンや位置を表す

\d, \s, \w)や数量({3,10})を表すREGular EXpression(regex):
通常の文字と特殊メタ文字の組み合わせからなる文字列で、テキスト内のパターンや位置を表す

\d, \s, \w)や数量({3,10})を表すREGular EXpression(regex):
通常の文字と特殊メタ文字の組み合わせからなる文字列で、テキスト内のパターンや位置を表す

\d, \s, \w)や数量({3,10})を表すREGular EXpression(regex):
通常の文字と特殊メタ文字の組み合わせからなる文字列で、テキスト内のパターンや位置を表すもの

\d, \s, \w)や数量({3,10})を表すREGular EXpression(regex):
通常の文字と特殊メタ文字の組み合わせからなる文字列で、テキスト内のパターンや位置を表す
パターンの用途:
非常に強力かつ高速
import re

re.findall(r"#movies", "Love #movies! I had fun yesterday going to the #movies")
['#movies', '#movies']
import re

re.split(r"!", "Nice Place to eat! I'll come back! Excellent meat!")
['Nice Place to eat', " I'll come back", ' Excellent meat', '']
import re

re.sub(r"yellow", "nice", "I have a yellow car and a yellow house in a yellow neighborhood")
'I have a nice car and a nice house in a nice neighborhood'

re.findall(r"User\d", "The winners are: User9, UserN, User8")
['User9', 'User8']

re.findall(r"User\D", "The winners are: User9, UserN, User8")
['UserN']

re.findall(r"User\w", "The winners are: User9, UserN, User8")
['User9', 'UserN', 'User8']

re.findall(r"\W\d", "This skirt is on sale, only $5 today!")
['$5']

re.findall(r"Data\sScience", "I enjoy learning Data Science")
['Data Science']

re.sub(r"ice\Scream", "ice cream", "I really like ice-cream")
'I really like ice cream'
Pythonで学ぶ正規表現