NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Quantifiers and Empty Matches

Matching details. Quantifiers *, +, {n,m} (and their lazy counterparts) never repeat after an empty match when the minimum number n has been matched. This rule prevents quantifiers from entering infinite loops on empty matches when m is infinite (although the rule applies even if m is not infinite).

For example, (a?)* matches "aaa" and captures substrings in the pattern (a)(a)(a)(). Note that there is no fifth empty capture, because the fourth empty capture causes the quantifier to stop repeating.

Similarly, (a\1|(?(1)\1)){0,2} matches the empty string rather than "a" because it never tries the expansion ()(a): the {0,2} quantifier only allows empty matches in the last iteration. In contrast, (a\1|(?(1)\1)){2} actually matches "a", because it does try ()(a) because the minimum number of iterations, 2, forces the engine to repeat after an empty match.