Open In App

Ruby | Regexp encoding() function

Improve
Improve
Like Article
Like
Save
Share
Report

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


Last Updated : 17 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads