Ruby Regexp fixed_encoding?() 函数
Regexp#fixed_encoding?() : fixed_encoding?() 是 Regexp 类的一个方法,用于检查正则表达式是否适用于任何 ASCII 兼容编码的字符串。
语法。Regexp.force_encoding??()
参数。Regexp值
返回:true – 如果rxp适用于任何ASCII兼容编码的字符串,否则返回false。
例子 #1 :
# Ruby code for Regexp.fixed_encoding?() method
# declaring Regexp value
reg_a = /a/
# declaring Regexp value
reg_b = /geeks/
# declaring Regexp value
reg_c = /a/
# fixed_encoding? method
puts "Regexp fixed_encoding? form : #{reg_a.fixed_encoding?}\n\n"
puts "Regexp fixed_encoding? form : #{reg_b.fixed_encoding?}\n\n"
puts "Regexp fixed_encoding? form : #{reg_c.fixed_encoding?}\n\n"
输出:
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
例子 #2 :
# Ruby code for Regexp.fixed_encoding?() method
# declaring Regexp value
reg_a = /geeks/
# declaring Regexp value
reg_b = /problem/
# declaring Regexp value
reg_c = /code/
# fixed_encoding? method
puts "Regexp fixed_encoding? form : #{reg_a.fixed_encoding?}\n\n"
puts "Regexp fixed_encoding? form : #{reg_b.fixed_encoding?}\n\n"
puts "Regexp fixed_encoding? form : #{reg_c.fixed_encoding?}\n\n"
输出:
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false