Ruby | Regexp fixed_encoding?() function
Last Updated :
17 Dec, 2019
Regexp#fixed_encoding?() : fixed_encoding?() is a Regexp class method which checks whether the regular expression is applicable to a string with any ASCII compatible encoding.
Syntax: Regexp.force_encoding??()
Parameter: Regexp values
Return: true – if the rxp is applicable to a string with any ASCII compatible encoding otherwise return false
Example #1 :
reg_a = /a/
reg_b = /geeks/
reg_c = /a/
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"
|
Output :
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
Example #2 :
reg_a = /geeks/
reg_b = /problem/
reg_c = /code/
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"
|
Output :
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
Regexp fixed_encoding? form : false
Share your thoughts in the comments
Please Login to comment...