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

Version Path
facets-2.0.0 lib/core/facets/string/regesc.rb
facets-2.0.1 lib/core/facets/string/regesc.rb
facets-2.0.2 lib/core/facets/string/regesc.rb
facets-2.1.0 lib/core/facets/string/regesc.rb
facets-2.1.1 lib/core/facets/string/regesc.rb
facets-2.1.2 lib/core/facets/string/regesc.rb
facets-2.0.3 lib/core/facets/string/regesc.rb
facets-2.0.5 lib/core/facets/string/regesc.rb
facets-2.0.4 lib/core/facets/string/regesc.rb
facets-2.1.3 lib/core/facets/string/regesc.rb