DEV Community

wataken44
wataken44

Posted on

getting regex in a quick way

create snippets

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

# escape.rb

def main()
    ARGV.each do |arg|
        puts(Regexp.escape(arg))
    end
end

if __FILE__ == $0 then
    main()
end
Enter fullscreen mode Exit fullscreen mode

run

$ ./escape.rb "http://www.google.com/"
http://www\.google\.com/
Enter fullscreen mode Exit fullscreen mode

:D

Top comments (0)