Guest User

Untitled

a guest
Feb 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #!/usr/bin/env ruby -w
  2.  
  3. # Trying to dynamically create a regexp object like so => /\\d|\\w|\+|\w*|\d*/
  4. terms = %w[\\d \\w \+ \w* \d*]
  5. create_regex = terms.join("|")
  6.  
  7. # double-escaped terms are 'corrected'
  8. puts create_regex # => \d|\w|\+|\w*|\d*
  9. x = Regexp.compile(create_regex)
  10. # double-escaped elements are 'corrected'
  11. puts x # => (?-mix:\d|\w|\+|\w*|\d*)
  12.  
  13. # try it without double quotes
  14. create_regex = '\\d|\\w|\+|\w*|\d*'
  15. x = Regexp.compile(create_regex)
  16. # double-escaped elements are 'corrected' again
  17. puts x # => (?-mix:\d|\w|\+|\w*|\d*)
Add Comment
Please, Sign In to add comment