Ruby Regexp encoding()函数
Regexp#encoding() : encoding()是Regexp类的一个方法,用于返回正则表达式的编码值。
语法。Regexp.encoding()
参数。Regexp值
返回:正则表达式的编码值
例子 #1 :
# Ruby code for Regexp.encoding() method
# declaring Regexp value
reg_a = /a/
# declaring Regexp value
reg_b = /geeks/
# declaring Regexp value
reg_c = /a/
# encoding method
puts "Regexp encoding form : #{reg_a.encoding}\n\n"
puts "Regexp encoding form : #{reg_b.encoding}\n\n"
puts "Regexp encoding form : #{reg_c.encoding}\n\n"
输出:
Regexp encoding form : US-ASCII
Regexp encoding form : US-ASCII
Regexp encoding form : US-ASCII
例子 #2 :
# Ruby code for Regexp.encoding() method
# declaring Regexp value
reg_a = /geeks/
# declaring Regexp value
reg_b = /problem/
# declaring Regexp value
reg_c = /code/
# encoding method
puts "Regexp encoding form : #{reg_a.encoding}\n\n"
puts "Regexp encoding form : #{reg_b.encoding}\n\n"
puts "Regexp encoding form : #{reg_c.encoding}\n\n"
输出:
Regexp encoding form : US-ASCII
Regexp encoding form : US-ASCII
Regexp encoding form : US-ASCII