Regular Expression Reference: Quantifiers

FeatureSyntaxDescriptionExampleJGsoft Python JavaScript VBScript XRegExp .NET Java ICU RE2 Perl PCRE PCRE2 PHP Delphi R Ruby std::regex Boost Tcl POSIX GNU Oracle XML XPath
Greedy quantifier ? (question mark) Makes the preceding item optional. Greedy, so the optional item is included in the match if possible. abc? matches abc or ab YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
extended
egrep
awk
ECMA
extended
egrep
awk
YESextendedextendedYESYESYES
Greedy quantifier \? Makes the preceding item optional. Greedy, so the optional item is included in the match if possible. abc\? matches abc or ab nonononononononononononononononononononobasicnonono
Lazy quantifier ?? Makes the preceding item optional. Lazy, so the optional item is excluded in the match if possible. abc?? matches ab or abc YESYESYESYESYESYESYESYESdefaultYESYESYESYESYESYESYESECMAECMAYESnonoYESnoYES
Possessive quantifier ?+ Makes the preceding item optional. Possessive, so if the optional item can be matched, then the quantifier won’t give up its match even if the remainder of the regex fails. abc?+c matches abcc but not abc YES3.11nonononoYESYESnoYESYESYESYESYESYES1.9noECMA
1.42
nononononono
Greedy quantifier * (star) Repeats the previous item zero or more times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is not matched at all. ".*" matches "def" "ghi" in abc "def" "ghi" jkl YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYES
Lazy quantifier *? Repeats the previous item zero or more times. Lazy, so the engine first attempts to skip the previous item, before trying permutations with ever increasing matches of the preceding item. ".*?" matches "def" and "ghi" in abc "def" "ghi" jkl YESYESYESYESYESYESYESYESdefaultYESYESYESYESYESYESYESECMAECMAYESnonoYESnoYES
Possessive quantifier *+ Repeats the previous item zero or more times. Possessive, so as many items as possible will be matched, without trying any permutations with less matches even if the remainder of the regex fails. ".*+" can never match anything YES3.11nonononoYESYESnoYESYESYESYESYESYES1.9noECMA
1.42
nononononono
Greedy quantifier + (plus) Repeats the previous item once or more. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only once. ".+" matches "def" "ghi" in abc "def" "ghi" jkl YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
extended
egrep
awk
ECMA
extended
egrep
awk
YESextendedextendedYESYESYES
Greedy quantifier \+ Repeats the previous item once or more. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only once. ".\+" matches "def" "ghi" in abc "def" "ghi" jkl nonononononononononononononononononononobasicnonono
Lazy quantifier +? Repeats the previous item once or more. Lazy, so the engine first matches the previous item only once, before trying permutations with ever increasing matches of the preceding item. ".+?" matches "def" and "ghi" in abc "def" "ghi" jkl YESYESYESYESYESYESYESYESdefaultYESYESYESYESYESYESYESECMAECMAYESnonoYESnoYES
Possessive quantifier ++ Repeats the previous item once or more. Possessive, so as many items as possible will be matched, without trying any permutations with less matches even if the remainder of the regex fails. ".++" can never match anything YES3.11nonononoYESYESnoYESYESYESYESYESYES1.9noECMA
1.42
nononononono
Fixed quantifier {n} where n is an integer >= 1 Repeats the previous item exactly n times. a{3} matches aaa YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
extended
egrep
awk
ECMA
extended
egrep
awk
YESextendedextendedYESYESYES
Greedy quantifier {n,m} where n >= 0 and m >= n Repeats the previous item between n and m times. Greedy, so repeating m times is tried before reducing the repetition to n times. a{2,4} matches aaaa, aaa or aa YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
extended
egrep
awk
ECMA
extended
egrep
awk
YESextendedextendedYESYESYES
Greedy quantifier {n,} where n >= 0 Repeats the previous item at least n times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only n times. a{2,} matches aaaaa in aaaaa YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
extended
egrep
awk
ECMA
extended
egrep
awk
YESextendedextendedYESYESYES
Greedy quantifier {,m} where m >= 1 Repeats the previous item between zero and m times. Greedy, so repeating m times is tried before reducing the repetition to zero times. a{,4} matches aaaa, aaa, aa, a, or the empty string V2YESwith /u errornononoerrorerrorno5.36
5.22 error
no10.43nono4.4.01.9
1.8 error
ECMA
extended
egrep
awk
error
ECMA 1.38–1.57
extended 1.38–1.89
egrep 1.38–1.89
awk 1.38–1.89
error
nonoextendednoerrorerror
Fixed quantifier \{n\} where n is an integer >= 1 Repeats the previous item exactly n times. a\{3\} matches aaa nonononononononononononononononobasic
grep
basic
grep
nobasicbasicnonono
Greedy quantifier \{n,m\} where n >= 0 and m >= n Repeats the previous item between n and m times. Greedy, so repeating m times is tried before reducing the repetition to n times. a\{2,4\} matches aaaa, aaa or aa nonononononononononononononononobasic
grep
basic
grep
nobasicbasicnonono
Greedy quantifier \{n,\} where n >= 0 Repeats the previous item at least n times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only n times. a\{2,\} matches aaaaa in aaaaa nonononononononononononononononobasic
grep
basic
grep
nobasicbasicnonono
Greedy quantifier \{,m\} where m >= 1 Repeats the previous item between zero and m times. Greedy, so repeating m times is tried before reducing the repetition to zero times. a\{,4\} matches aaaa, aaa, aa, a, or the empty string nonononononononononononononononononononobasicnonono
Lazy quantifier {n,m}? where n >= 0 and m >= n Repeats the previous item between n and m times. Lazy, so repeating n times is tried before increasing the repetition to m times. a{2,4}? matches aa, aaa or aaaa YESYESYESYESYESYESYESYESdefaultYESYESYESYESYESYESYESECMAECMAYESnonoYESnoYES
Lazy quantifier {n,}? where n >= 0 Repeats the previous item n or more times. Lazy, so the engine first matches the previous item n times, before trying permutations with ever increasing matches of the preceding item. a{2,}? matches aa in aaaaa YESYESYESYESYESYESYESYESdefaultYESYESYESYESYESYESYESECMAECMAYESnonoYESnoYES
Lazy quantifier {,m}? where m >= 1 Repeats the previous item between zero and m times. Lazy, so repeating zero times is tried before increasing the repetition to m times. a{,4}? matches the empty string, a, aa, aaa or aaaa V2YESwith /u errornononoerrorerrorno5.36
5.22 error
no10.43nono4.4.01.9
1.8 error
ECMA
extended
egrep
awk
error
ECMA 1.38–1.57
extended 1.38–1.89
egrep 1.38–1.89
awk 1.38–1.89
error
nonononoerrorerror
Possessive quantifier {n,m}+ where n >= 0 and m >= n Repeats the previous item between n and m times. Possessive, so as many items as possible up to m will be matched, without trying any permutations with less matches even if the remainder of the regex fails. a{2,4}+a matches aaaaa but not aaaa YES3.11nonononoYESYESnoYESYESYESYESYESYESnonoECMA
1.42
nononononono
Possessive quantifier {n,}+ where n >= 0 Repeats the previous item n or more times. Possessive, so as many items as possible will be matched, without trying any permutations with less matches even if the remainder of the regex fails. a{2,}+a never matches anything YES3.11nonononoYESYESnoYESYESYESYESYESYESnonoECMA
1.42
nononononono
Possessive quantifier {,m}+ where m >= 1 Repeats the previous item between zero and m times. Possessive, so as many items as possible up to m will be matched, without trying any permutations with less matches even if the remainder of the regex fails. a{,4}+a matches aaaaa but not aaaa YES3.11nonononoYESYESnoYESYESYESYESYESYESnonoECMA
1.42
nononononono
Bounded quantifier {n} and {n,m} with n or m = 1000 Bounded quantifiers allow at least 1,000 repetitions as the upper bound. a{1000} matches 1,000 letters. YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESerrorerrorYESYESYESYES
Bounded quantifier {n} and {n,m} with n or m = 32766 Bounded quantifiers allow at least 32,766 (215−2) repetitions as the upper bound. a{32766} matches 32,766 letters. YESYESYESYESYESYESYESYESerrorYESYESYESYESYESYESYESYESYESerrorerrorerrorYESYESYES
Bounded quantifier {n} and {n,m} with n or m = 65534 Bounded quantifiers allow at least 65,534 (216−2) repetitions as the upper bound. a{65534} matches 65,534 letters. YESYESYESYESYESYESYESYESerror5.30
5.14 error
YESYESYESYESYES1.9
1.8 error
YESYESerrorerrorerrorYESYESYES
Bounded quantifier {n} and {n,m} with n or m = 65535 Bounded quantifiers allow at least 65,535 (216−1) repetitions as the upper bound. a{65535} matches 65,535 letters. YESYESYESYESYESYESYESYESerror5.38
5.14 error
YESYESYESYESYES1.9
1.8 error
YESYESerrorerrorerrorYESYESYES
Bounded quantifier {n} and {n,m} with n or m = 65536 Bounded quantifiers allow at least 65,536 (216) repetitions as the upper bound. a{65536} matches 65,536 letters. YES2.7
2.5 error
2.4 fail
YESYESYESYESYESYESerror5.38
5.14 error
errorerrorerrorerrorerror1.9
1.8 error
VC’12YESerrorerrorerrorfailYESYES
Bounded quantifier {n} and {n,m} with n or m = 100000 Bounded quantifiers allow at least 100,000 repetitions as the upper bound. a{100000} matches 100,000 letters. YES2.7
2.5 error
2.4 fail
YESYESYESYESYESYESerror5.38
5.14 error
errorerrorerrorerrorerror1.9
1.8 error
VC’12YESerrorerrorerrorfailYESYES
Bounded quantifier {n} and {n,m} with n or m = 16777215 Bounded quantifiers allow at least 16,777,215 (1024-1) repetitions as the upper bound. a{16777215} matches 16,777,215 letters. YES2.7
2.5 error
2.4 fail
YESYESYESYESYESYESerror5.38
5.14 error
errorerrorerrorerrorerrorerrorVC’12YESerrorerrorerrorfailYESYES
Bounded quantifier {n} and {n,m} with n or m = 999999999 Bounded quantifiers allow at least 999,999,999 repetitions as the upper bound. a{999999999} matches 999,999,999 letters. YES2.7
2.5 error
2.4 fail
YESYESYESYESYESerrorerror5.38
5.14 error
errorerrorerrorerrorerrorerrorVC’12YESerrorerrorerrorfailYESYES
Bounded quantifier {n} and {n,m} with n or m = 2147483646 Bounded quantifiers allow at least 2,147,483,646 (231−2) repetitions as the upper bound. a{2147483646} matches 2,147,483,646 letters. no2.7
2.5 error
2.4 fail
YESYESYESYESYESerrorerror5.38
5.14 error
errorerrorerrorerrorerrorerrorVC’12YESerrorerrorerrorfailYESYES
Bounded quantifier {n} and {n,m} with n or m = 2147483647 Bounded quantifiers allow at least 2,147,483,647 (231−1) repetitions as the upper bound. a{2147483647} matches 2,147,483,647 letters. no2.7
2.5 error
2.4 fail
YESYESYESYESYESerrorerrorerrorerrorerrorerrorerrorerrorerrorVC’12YESerrorerrorerrorfailYESYES
FeatureSyntaxDescriptionExampleJGsoft Python JavaScript VBScript XRegExp .NET Java ICU RE2 Perl PCRE PCRE2 PHP Delphi R Ruby std::regex Boost Tcl POSIX GNU Oracle XML XPath

AltStyle によって変換されたページ (->オリジナル) /