require 'cgi'

CGI.escape('^') => "%5E"