標準ライブラリ
正規表現(regexp)
import re
print "aaa".replace( "aa", "b" );
print re.findall( r"\bf[a-z]+", "foo bar fff" )
print re.sub( r"\bf[a-z]+", "ddd", "foo bar fff" )
if re.match("^#include", s ) != None :
print "not match"
re.search() は文字列に含まれる任意の部分文字列を探す
re.match() は文字列の先頭にある部分文字列を探す
WARNING
if re.match("include", s) != None :
print s
search ならば途中の文字列でも検索してくれる
if re.search("include", s) != None :
print s
if re.search("include", s) == None :
print "not match"
WARNING
文字としての | を指定する時はエスケープをすること
if re.match( "|aaa", "bbb" ) != None:
print "match"
if re.match( "\|aaa", "bbb" ) != None:
print "match"