'John Merlino' via Ruby on Rails: Talk
2014-Aug-15 01:28 UTC
What is the question mark inside this regex doing?
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 rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.