Using ruby regexp I get the following results:
>> 'foobar'[/o+/]
=> "oo"
>> 'foobar'[/o*/]
=> ""
But:
>> 'foobar'[/fo+/]
=> "foo"
>> 'foobar'[/fo*/]
=> "foo"
The documentation says:
*: zero or more repetitions of the preceding
+: one or more repetitions of the preceding
So i expect that ‘foobar'[/o*/] returns the same result as ‘foobar'[/o+/]
Does anybody have an explanation for that
'foobar'[/o*/]is matching the zeroos that appear before thef, at position 0'foobar'[/o+/]can’t match there because there needs to be at least 1o, so it instead matches all theos from position 1Specifically, the matches you are seeing are
'foobar'[/o*/]=>'<>foobar''foobar'[/o+/]=>'f<oo>bar'