Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby -w
- # Trying to dynamically create a regexp object like so => /\\d|\\w|\+|\w*|\d*/
- terms = %w[\\d \\w \+ \w* \d*]
- create_regex = terms.join("|")
- # double-escaped terms are 'corrected'
- puts create_regex # => \d|\w|\+|\w*|\d*
- x = Regexp.compile(create_regex)
- # double-escaped elements are 'corrected'
- puts x # => (?-mix:\d|\w|\+|\w*|\d*)
- # try it without double quotes
- create_regex = '\\d|\\w|\+|\w*|\d*'
- x = Regexp.compile(create_regex)
- # double-escaped elements are 'corrected' again
- puts x # => (?-mix:\d|\w|\+|\w*|\d*)
Add Comment
Please, Sign In to add comment