Ruby | Regexp fixed_encoding?() function

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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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"

chevron_right


Output :

Regexp fixed_encoding? form : false

Regexp fixed_encoding? form : false

Regexp fixed_encoding? form : false

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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"

chevron_right


Output :

Regexp fixed_encoding? form : false

Regexp fixed_encoding? form : false

Regexp fixed_encoding? form : false

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.