この記事は Python Tips Advent Calendar 2012 24日目の記事です。 Python の正規表現には、便利な機能がいくつかあります。ということで、いくつか見ていきましょう。 コメント機能 >>> import re >>> re.compile(r''' ... ^ # start of a line ... \[font # the font tag ... (?:=(?P<size> # optional [font=+size] ... [-+][0-9]{1,2} # size specification ... ))? ... \] # end of tag ... (.*?) # text between the tags ... \[/font\] # end of the tag ... ''', re.VERBOSE) #doctest: +E