Replacement Reference |
Characters |
Matched Text & Backreferences |
Context & Case Conversion |
Conditionals |
Feature | Syntax | Description | Example | JGsoft | .NET | Java | Perl | PCRE | PCRE2 | PHP | Delphi | R | JavaScript | VBScript | XRegExp | Python | Ruby | std::regex | Boost | Tcl ARE | POSIX BRE | POSIX ERE | GNU BRE | GNU ERE | 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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA extended egrep awk | ECMA extended egrep awk | YES | no | YES | no | YES | YES | YES | YES |
Greedy quantifier | \? | Makes the preceding item optional. Greedy, so the optional item is included in the match if possible. | abc\? matches abc or ab | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | YES | no | no | no | no |
Lazy quantifier | ?? | Makes the preceding item optional. Lazy, so the optional item is excluded in the match if possible. | abc?? matches ab or abc | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | 10gR2 | no | YES |
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 | YES | no | YES | 5.10 | YES | YES | YES | YES | YES | no | no | no | no | 1.9 | no | ECMA 1.42–1.85 | no | no | no | no | no | no | no | no |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | 10gR2 | no | YES |
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 | YES | no | YES | 5.10 | YES | YES | YES | YES | YES | no | no | no | no | 1.9 | no | ECMA 1.42–1.85 | no | no | no | no | no | no | no | no |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA extended egrep awk | ECMA extended egrep awk | YES | no | YES | no | YES | YES | YES | YES |
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 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | YES | no | no | no | no |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | 10gR2 | no | YES |
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 | YES | no | YES | 5.10 | YES | YES | YES | YES | YES | no | no | no | no | 1.9 | no | ECMA 1.42–1.85 | no | no | no | no | no | no | no | no |
Fixed quantifier | {n} where n is an integer >= 1 | Repeats the previous item exactly n times. | a{3} matches aaa | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA extended egrep awk | ECMA extended egrep awk | YES | no | YES | no | YES | YES | YES | YES |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA extended egrep awk | ECMA extended egrep awk | YES | no | YES | no | YES | YES | YES | YES |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA extended egrep awk | ECMA extended egrep awk | YES | no | YES | no | YES | YES | YES | YES |
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 | V2 | no | no | no | no | no | no | no | no | no | no | no | YES | 1.9 | no | no | no | no | no | no | YES | no | no | no |
Fixed quantifier | \{n\} where n is an integer >= 1 | Repeats the previous item exactly n times. | a\{3\} matches aaa | no | no | no | no | no | no | no | no | no | no | no | no | no | no | basic grep | basic grep | no | YES | no | YES | no | no | no | no |
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 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | basic grep | basic grep | no | YES | no | YES | no | no | no | no |
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 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | basic grep | basic grep | no | YES | no | YES | no | no | no | no |
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 | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | no | YES | no | no | no | no |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | 10gR2 | no | YES |
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 | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | YES | ECMA | ECMA | YES | no | no | no | no | 10gR2 | no | YES |
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 | V2 | no | no | no | no | no | no | no | no | no | no | no | YES | 1.9 | no | no | no | no | no | no | no | no | no | no |
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 | YES | no | YES | 5.10 | YES | YES | YES | YES | YES | no | no | no | no | no | no | ECMA 1.42–1.85 | no | no | no | no | no | no | no | no |
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 | YES | no | YES | 5.10 | YES | YES | YES | YES | YES | no | no | no | no | no | no | ECMA 1.42–1.85 | no | no | no | no | no | no | no | no |
Feature | Syntax | Description | Example | JGsoft | .NET | Java | Perl | PCRE | PCRE2 | PHP | Delphi | R | JavaScript | VBScript | XRegExp | Python | Ruby | std::regex | Boost | Tcl ARE | POSIX BRE | POSIX ERE | GNU BRE | GNU ERE | Oracle | XML | XPath |
| Quick Start | Tutorial | Tools & Languages | Examples | Reference | Book Reviews |
| Introduction | Table of Contents | Quick Reference | Characters | Basic Features | Character Classes | Shorthands | Anchors | Word Boundaries | Quantifiers | Unicode | Capturing Groups & Backreferences | Named Groups & Backreferences | Special Groups | Mode Modifiers | Recursion & Balancing Groups |
| Characters | Matched Text & Backreferences | Context & Case Conversion | Conditionals |
Page URL: https://www.regular-expressions.info/refrepeat.html
Page last updated: 16 August 2024
Site last updated: 06 November 2024
Copyright © 2003-2024 Jan Goyvaerts. All rights reserved.