Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Regexp inspect() function

  • Last Updated : 17 May, 2021
Geek Week

Regexp#inspect() is a Regexp class method which produces a formatted string-version of regular expression.
 

Syntax: Regexp.inspect()
Parameter: Regexp values
Return: a formatted string-version of regular expression

Example #1 : 
 

Ruby




# Ruby code for Regexp.inspect() method
 
# declaring Regexp value
reg_a = /a/
 
# declaring Regexp value
reg_b = /geeks/
 
# declaring Regexp value
reg_c = /a/
 
 
#  inspect method
puts "Regexp inspect form : #{reg_a.inspect}\n\n"
 
puts "Regexp inspect form : #{reg_b.inspect}\n\n"
 
puts "Regexp inspect form : #{reg_c.inspect}\n\n"

Output : 
 



Regexp inspect form : /a/

Regexp inspect form : /geeks/

Regexp inspect form : /a/

Example #2 :
 

Ruby




# Ruby code for Regexp.inspect() method
 
# declaring Regexp value
reg_a = /geeks/
 
# declaring Regexp value
reg_b = /problem/
 
# declaring Regexp value
reg_c = /code/
 
 
#  inspect method
puts "Regexp inspect form : #{reg_a.inspect}\n\n"
 
puts "Regexp inspect form : #{reg_b.inspect}\n\n"
 
puts "Regexp inspect form : #{reg_c.inspect}\n\n"

Output : 
 

Regexp inspect form : /geeks/

Regexp inspect form : /problem/

Regexp inspect form : /code/

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :