Skip to content

Instantly share code, notes, and snippets.

@vrinek
Created November 21, 2011 14:55
Show Gist options
  • Select an option

  • Save vrinek/1382849 to your computer and use it in GitHub Desktop.

Select an option

Save vrinek/1382849 to your computer and use it in GitHub Desktop.
Convert Ruby Regexp to JavaScript RegExp
class Regexp
def to_javascript
Regexp.new(inspect.sub('\\A','^').sub('\\Z','$').sub('\\z','$').sub(/^\//,'').sub(/\/[a-z]*$/,'').gsub(/\(\?#.+\)/, '').gsub(/\(\?-\w+:/,'('), self.options).inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment