Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Regexp encoding() function

  • Last Updated : 17 Dec, 2019

Regexp#encoding() : encoding() is a Regexp class method which returns the encoding value of the regular expressions.

Syntax: Regexp.encoding()

Parameter: Regexp values

Return: encoding value of the regular expressions

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

Output :

Regexp encoding form : US-ASCII

Regexp encoding form : US-ASCII

Regexp encoding form : US-ASCII

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

Output :

Regexp encoding form : US-ASCII

Regexp encoding form : US-ASCII

Regexp encoding form : US-ASCII

My Personal Notes arrow_drop_up
Recommended Articles
Page :