зеркало из https://github.com/github/ruby.git
Document {n}? regexp pattern is optional and not non-greedy [ci skip]
While not consistent with {n,}?, {,m}?, and {n,m}?, it is arguably more useful, as otherwise the ? would have no effect. Fixes [Bug #15583]
This commit is contained in:
Родитель
e82719c651
Коммит
cd0e208963
|
@ -189,8 +189,11 @@ At least one uppercase character ('H'), at least one lowercase character
|
||||||
Repetition is <i>greedy</i> by default: as many occurrences as possible
|
Repetition is <i>greedy</i> by default: as many occurrences as possible
|
||||||
are matched while still allowing the overall match to succeed. By
|
are matched while still allowing the overall match to succeed. By
|
||||||
contrast, <i>lazy</i> matching makes the minimal amount of matches
|
contrast, <i>lazy</i> matching makes the minimal amount of matches
|
||||||
necessary for overall success. A greedy metacharacter can be made lazy by
|
necessary for overall success. Most greedy metacharacters can be made lazy
|
||||||
following it with <tt>?</tt>.
|
by following them with <tt>?</tt>. For the <tt>{n}</tt> pattern, because
|
||||||
|
it specifies an exact number of characters to match and not a variable
|
||||||
|
number of characters, the <tt>?</tt> metacharacter instead makes the
|
||||||
|
repeated pattern optional.
|
||||||
|
|
||||||
Both patterns below match the string. The first uses a greedy quantifier so
|
Both patterns below match the string. The first uses a greedy quantifier so
|
||||||
'.+' matches '<a><b>'; the second uses a lazy quantifier so '.+?' matches
|
'.+' matches '<a><b>'; the second uses a lazy quantifier so '.+?' matches
|
||||||
|
|
Загрузка…
Ссылка в новой задаче