Module: Regexp::ClassMethods

Included in:
Regexp
Defined in:
app/models/regexp.rb

Instance Method Summary collapse

Instance Method Details

#delimiter_regexp(delimiter) ⇒ Object

A delimiter is generally not at the end (like commas)


52
53
54
55
# File 'app/models/regexp.rb', line 52

def delimiter_regexp(delimiter)
	raise "delimiters must be single characters not #{delimiter.inspect}." if delimiter.length!=1
	/([^#{delimiter}]*)(?:#{delimiter}([^#{delimiter}]*))*/
end

#promote(node) ⇒ Object


23
24
25
26
27
28
29
30
31
# File 'app/models/regexp.rb', line 23

def promote(node)
	if node.instance_of?(String) then 
		Regexp.new(Regexp.new(Regexp.escape(node)))
	elsif node.instance_of?(Regexp) then 
		node
	else
		raise "unexpected node=#{node.inspect}"
	end #if
end

#regexp_error(regexp_string, options = Default_options) ⇒ Object

regexp_rescued


40
41
42
43
44
45
# File 'app/models/regexp.rb', line 40

def regexp_error(regexp_string, options=Default_options)
	raise "expecting regexp_string=#{regexp_string.inspect}" unless regexp_string.instance_of?(String)
	return Regexp.new(regexp_string, options)
rescue RegexpError => exception
	return exception
end

#regexp_rescued(regexp_string, options = Default_options) ⇒ Object

Rescue bad regexp and return nil Example regexp with unbalanced bracketing characters


34
35
36
37
38
39
# File 'app/models/regexp.rb', line 34

def regexp_rescued(regexp_string, options=Default_options)
	raise "expecting regexp_string=#{regexp_string}" unless regexp_string.instance_of?(String)
	return Regexp.new(regexp_string, options)
rescue RegexpError
	return nil
end

#terminator_regexp(delimiter) ⇒ Object

A terminator is a delimiter that is at the end (like new line)


47
48
49
50
# File 'app/models/regexp.rb', line 47

def terminator_regexp(delimiter)
#	raise "delimiter must be single characters not #{delimiter}." if delimiter.length!=1
	/([^#{delimiter}]*)(?:#{delimiter}([^#{delimiter}]*))*/
end