I thought the ? matches zero or one occurrence of a pattern. However in
this example:
def show_regexp(string, pattern)
match = pattern.match(string)
if match
"#{match.pre_match}->#{match[0]}<-#{match.post_match}"
else
"no match"
end
end
a = "The moon is made of cheese"
show_regexp(a, /\s.*?\s/) #=> The-> moon <-is made of cheese
What exactly is the ? doing?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/8d5efdaa-d690-4a34-8a84-e7c1c3696dd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.