An unescaped vertical bar(|) matches either the regular expression that precedes it or the regular expression that follows it. : Regexps Group « Development « Ruby
An unescaped vertical bar(|) matches either the regular expression that precedes it or the regular expression that follows it.
def show_regexp(a, re) if a =~ re
"#{$`}<<#{$&}>>#{$'}" else
"no match" end end
a = "this is a test"
show_regexp(a, /d|e/)
show_regexp(a, /al|lu/)
show_regexp(a, /is test|this is/)