Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
import re # rを付けることを推奨。 # バックスラッシュをそのままで分かりやすいため。 content = r'hellow python, 123, end.' pattern = 'hel' result = re.match(pattern, content) if result: #none以外の場合 print(result) # output:<_sre.SRE_Match object; span=(0, 3), match='hel'> print(result.span()) # output:(0, 3) print(result.group()) # output:hel
正規表現についてよく使いそうなものをメモ。 ・Mac ・python <メモ内容> ① ”.”は 改行以外の任意の1文字(数字含む) ② matchは、先頭からマッチするかを判定する関数、マッチする場合はmatchオブジェクト(正規表現をまとめたもの)を返し、マッチしなければNONEを返す。 ③ searchは、途中でマッチするかどうかを判定する関数。2箇所ある場合は最初の1箇所のみ返す。マッチする場合はmatchオブジェクトを返し、マッチしなければNONEを返す。 ④ splitは指定した文字で分割する関数、返り値はリスト型 ⑤ findallは、指定した文字を全て返す関数、返り値はリスト型 (1)例題 import re text1 = 'abcde' text2 = 'a' text3 = '1234' text4 = 'a1234' text5 = 'a1234a567' text
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く