Ruby | Regexp encoding() function
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 :
reg_a = /a/
reg_b = /geeks/
reg_c = /a/
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 :
reg_a = /geeks/
reg_b = /problem/
reg_c = /code/
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
Share your thoughts in the comments
Please Login to comment...