Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def common_sub(*strings)
- reg = Regexp.new strings.shift.split(//).map { |i| "#{i}?" }.join("")
- c = nil
- strings.each do |s|
- return nil unless m = reg.match(s)
- if c
- c = m[0] if c.size > m[0].size
- else
- c = m[0]
- end
- end
- return c
- end
- p common_sub("foobar", "foobaz", "foowhoo")
Add Comment
Please, Sign In to add comment