2009-01-02から1日間の記事一覧

lispとrubyとpythonと その6 正規表現(python)

Pythonでの正規表現。 #reモジュールを使う import re #正規表現をコンパイル #r""でrawstringになって\が特別な意味を持たなくなる。 #正規表現を書くときにはこっちを使うと便利 #re.compileの引数で設定変更できる(大文字、小文字区別しないとか) rx = r…

lispとrubyとpythonと その6 正規表現(ruby)

Rubyでの正規表現。 # -*- coding: utf-8 -*- #正規表現リテラルは/で囲む #Regexp.new(...)でもいい rx = /(?<p>.*):\/\/(?<d>.*)\// target = "http://faroffsea.blogspot.com/" #matchの戻り値はMatchData captures = rx.match target #/(?<p>.*):\/\/(?<d>.*)\//.mat</d></p></d></p>…