def show_regexp(a, re) if a =~ re "#{$`}<<#{$&}>>#{$'}" else "no match" end end a = "this is a test" show_regexp(a, /\w+/) show_regexp(a, /\s.*\s/) show_regexp(a, /\s.*?\s/) show_regexp(a, /[aeiou]{2,99}/) show_regexp(a, /mo?o/)