Created
August 18, 2014 12:35
-
-
Save hzm-s/bb42aee24ea5cece897e to your computer and use it in GitHub Desktop.
配列をもとに正規表現オブジェクトをつくる ref: http://qiita.com/haazime/items/9b39af6708cc214b2651
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = %w(foo bar baz) | |
regexp = Regexp.union(words) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parts = [/^foo$/, /^bar/, /baz$/] | |
regexp = Regexp.union(parts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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