Sha256: 7be57300a10e4b4e74b1d5b14e6ed5697377ade985bd047b4089a120de9c3a04
Contents?: true
Size: 857 Bytes
Versions: 10
Compression:
Stored size: 857 Bytes
Contents
# TITLE: # # Regesc # # SUMMARY: # # Qucik and easy Regular expression from string. # # CREDIT: # # - Thomas Sawyer # class String # Escape string for Regexp use. def regesc Regexp.escape(self) end end module Kernel # Provides a shortcut to the Regexp.escape module method. # # Will be deprecated in favor of String#regesc. def resc(str) Regexp.escape(str) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TestStringRegesc < Test::Unit::TestCase def test_regesc a = "?" b = /#{a.regesc}/ assert( b =~ "?" ) end def test_resc assert_equal( Regexp.escape("'jfiw0[]4"), resc("'jfiw0[]4") ) assert_equal( Regexp.escape("/////"), resc("/////") ) end end =end
Version data entries
10 entries across 10 versions & 1 rubygems