#navi(../)
* 英字の大文字・小文字を区別せず比較する方法・re [#i5fd2410]
Pythonで英字の大文字・小文字を区別せずに比較する方法のサンプルコードを以下に記します。
#contents
#htmlinsertpcsp(ll-top.html,ll-sp.html)
* 関連記事 [#tb92c583]
-[[Pythonで文字列置換・replace>Python/サンプル/文字列の置換・replace]]
-[[Pythonで数値を文字列に変換する・str>Python/サンプル/数値を文字列に変換する・str]]
-[[Pythonで指定した文字で分割し配列(list)に格納する方法・split>Python/サンプル/指定した文字で分割し配列(list)に格納する方法・split]]
-[[Pythonで左右のスペース削除・strip, lstrip, rstrip>Python/サンプル/左右のスペース削除・strip, lstrip, rstrip]]
-[[Pythonでリストに格納されている要素に区切り文字を指定し出力する・join>Python/サンプル/リストに格納されている要素に区切り文字を指定し出力する・join]]
-[[Pythonで文字列の半角英字の大文字小文字化方法・upper,lower>Python/サンプル/半角英字の大文字小文字化方法・upper,lower]]
-[[Pythonで文字列のleft,mid,rightを実現する方法>Python/サンプル/文字列のleft,mid,rightを実現する方法]]
-[[Pythonで前方・後方文字列検索・find,rfind>Python/サンプル/前方・後方文字列検索・find,rfind]]
-[[Pythonでカンマ区切りの文字列をリストに入れる方法・split>Python/サンプル/カンマ区切りの文字列をリストに入れる方法]]
-[[Pythonでゼロパティングする方法・zfill>Python/サンプル/ゼロパティングする方法・zfill]]
-[[Pythonで英字の大文字・小文字を区別せず比較する方法・re>Python/サンプル/英字の大文字・小文字を区別せず比較する方法・re]]
* 英字の大文字・小文字を区別しないサンプルコード [#d0b4960f]
lower, upper, 正規表現のreモジュールを使ったサンプルコードです。
#ref(cmp.py)
import re
a = "HELLO WORLD"
b = "hello world"
if a == b:
print "same stringl\n"
if a.upper() == b.upper():
print "upper() : same string"
if a.lower() == b.lower():
print "lower() : same string"
if re.compile(a,re.IGNORECASE).match(b) != None:
print "re.cmpile... : same string"
実際に実行した時の出力です。
$ python cmp.py
upper() : same string
lower() : same string
re.cmpile... : same string
以上、Pythonで英字の大文字・小文字を区別せずに比較する方法でした。
#htmlinsertpcsp(ll-btm.html,ll-sp.html)