Skip to content

Instantly share code, notes, and snippets.

@hzm-s
Created August 18, 2014 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hzm-s/bb42aee24ea5cece897e to your computer and use it in GitHub Desktop.
Save hzm-s/bb42aee24ea5cece897e to your computer and use it in GitHub Desktop.
配列をもとに正規表現オブジェクトをつくる ref: http://qiita.com/haazime/items/9b39af6708cc214b2651
words = %w(foo bar baz)
regexp = Regexp.union(words)
parts = [/^foo$/, /^bar/, /baz$/]
regexp = Regexp.union(parts)
words = %w(foo bar baz)
regexp = Regexp.new(words.join('|'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment