Skip to content

Instantly share code, notes, and snippets.

@masui
Created May 18, 2012 13:34
Show Gist options
  • Save masui/2725301 to your computer and use it in GitHub Desktop.
Save masui/2725301 to your computer and use it in GitHub Desktop.
# 3の倍数にマッチする正規表現
require 'rubygems'
require 're_expand'
pat = "(0|1(0|1(0)*2)*(2|1(0)*1)|2(0|2(0)*1)*(1|2(0)*2))+"
pat.gsub!(/0/,'(0|3|6|9)')
pat.gsub!(/1/,'(1|4|7)')
pat.gsub!(/2/,'(2|5|8)')
pat.expand { |a|
puts a[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment