Sha256: dbf9c301db718f7906465c41d40ef2152ccf1f99d6fa4525ab8fce0fc9199b14

Contents?: true

Size: 748 Bytes

Versions: 9

Compression:

Stored size: 748 Bytes

Contents

module Aio::Base::Toolkit
  module Regexp
    class << self
      def to_reg(cmd)
        res = cmd.gsub(' ', '([^\s]*)\s+')
        res.insert(0, '^')
        res.insert(-1, '([^\s]*)$')
        return ::Regexp.new(res)
      end

      def blank
        return /^[\t]*$/
      end

      # 产生一个安全的正则表达式
      def safe(reg)
        res = reg.to_s.gsub(' ', '\s+')
        return ::Regexp.new(res)
      end

      # 将一个数组的正则表达式合并成为一个正则表达式
      def merge(arr_regs)
        str_arr = []
        arr_regs.each {|x| str_arr << x.to_s}
        new_reg = str_arr.join("|").gsub("?-mix:", "")
        new_reg = ::Regexp.new(new_reg)
        return new_reg
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
aio_elin-1.1.8 lib/aio/base/toolkit/regexp.rb
aio_elin-1.1.7 lib/aio/base/toolkit/regexp.rb
aio_elin-1.1.4 lib/aio/base/toolkit/regexp.rb
aio_elin-1.1.3 lib/aio/base/toolkit/regexp.rb
aio_elin-1.1.2 lib/aio/base/toolkit/regexp.rb
aio_elin-1.1.1 lib/aio/base/toolkit/regexp.rb
aio_elin-1.1.0 lib/aio/base/toolkit/regexp.rb
aio_elin-1.0.9 lib/aio/base/toolkit/regexp.rb
aio_elin-1.0.8 lib/aio/base/toolkit/regexp.rb