(Python)文字列の正規表現、(先頭、末尾の固定)

Pocket

正規表現とは、Pythonのみならず、ほかの言語(Java,C,PHP,Javascript)などにも出てくる概念です。
正規表現はある特定の文字列(パターン)が、検索対象の文字列に出現するかどうかを判定します。検索パターンが検索対象の一部だけでも一致すればOKである。

[^]は文字列の先頭を表す。
[$]は文字列の行末を表す。

(実行結果)
*******
(Pattern)ABA(search)ABA(match)OK
(Pattern)ABA(search)ABAA(match)OK
(Pattern)ABA(search)ABAAA(match)OK
(Pattern)ABA(search)AABA(match)OK
(Pattern)ABA(search)AAABA(match)OK
*******
(Pattern)^ABA(search)ABA(match)OK
(Pattern)^ABA(search)ABAA(match)OK
(Pattern)^ABA(search)ABAAA(match)OK
(Pattern)^ABA(search)AABA(match)NG
(Pattern)^ABA(search)AAABA(match)NG
*******
(Pattern)ABA$(search)ABA(match)OK
(Pattern)ABA$(search)ABAA(match)NG
(Pattern)ABA$(search)ABAAA(match)NG
(Pattern)ABA$(search)AABA(match)OK
(Pattern)ABA$(search)AAABA(match)OK
*******
(Pattern)^ABA$(search)ABA(match)OK
(Pattern)^ABA$(search)ABAA(match)NG
(Pattern)^ABA$(search)ABAAA(match)NG
(Pattern)^ABA$(search)AABA(match)NG
(Pattern)^ABA$(search)AAABA(match)NG

ブックマーク へのパーマリンク.

コメントは停止中です。