>> English << | česky | Deutsch | Español ZVON > Tutorials > Regular Expressions Tutorial
>> Example 17 << | Prev | Next | Contents | Regular Expressions

Description


By default any subpattern matches as many times as possible. This behaviour is changed to matching the minimum number if quantifier is followed with the question mark. Compare "*" (Case 1) with "*?" (Case 2), "+" (Case 3) with "+?" (Case 4), and "?" (Case 5) with "??" (Case 6).

Source


One ring to bring them all and in the darkness bind them

Case 1


Regular Expression: r.*
First match:One ring to bring them all and in the darkness bind them
All matches:One ring to bring them all and in the darkness bind them

Case 2


Regular Expression: r.*?
First match:One ring to bring them all and in the darkness bind them
All matches:One ring to bring them all and in the darkness bind them

Case 3


Regular Expression: r.+
First match:One ring to bring them all and in the darkness bind them
All matches:One ring to bring them all and in the darkness bind them

Case 4


Regular Expression: r.+?
First match:One ring to bring them all and in the darkness bind them
All matches:One ring to bring them all and in the darkness bind them

Case 5


Regular Expression: r.?
First match:One ring to bring them all and in the darkness bind them
All matches:One ring to bring them all and in the darkness bind them

Case 6


Regular Expression: r.??
First match:One ring to bring them all and in the darkness bind them
All matches:One ring to bring them all and in the darkness bind them