Sha256: 7e8a07ae7c44d8a44afd1d4ff9ded8885eabba30e7b867662f69e819a27656ed
Contents?: true
Size: 653 Bytes
Versions: 1
Compression:
Stored size: 653 Bytes
Contents
# Ruby to JavaScript regular expression converter class JSRegexp # Convert Ruby Regexp to JavaSript RegExp format # # @params regexp [Regexp, String] a Ruby regular expression # @return [String] JavaSript regular expression represented as a string def self.convert(regexp) str_regexp = regexp.inspect .sub(/^\// , '') .sub(/\/[a-z]*$/ , '') .sub('\\A', '^') .sub('\\G', '^') .sub('\\Z', '$') .sub('\\z', '$') .gsub('\\R', '') .gsub('\\a', '') .gsub('\\e', '') .gsub(/\(\?#.+\)/, '') .gsub(/\(\?-\w+:/, '(') .gsub(/\s/, '') Regexp.new(str_regexp).source end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jsregexp-0.1.2 | lib/jsregexp/jsregexp.rb |