Regex 高度 Syntax リファレンス
リファレンス 用 高度 regex 機能: lookaround, backreferences, atomic groups, および possessive quantifiers.
Lookaround Assertions
Lookahead (?=...) and negative lookahead (?!...) assert what follows without consuming. Lookbehind (?<=...) and negative lookbehind (?<!...) assert what precedes. Fixed-width lookbehind is widely supported; variable-width is supported in .NET, PCRE 7.7+, and ECMAScript 2018+. Lookaround does not consume characters, allowing overlapping matches. Nested lookaround can express complex conditions but may be slow or unsupported. Lookaround is zero-width: it matches a position, not text.
- (?=...)
- Positive lookahead
- (?!...)
- Negative lookahead
- (?<=...)
- Positive lookbehind
asserts ahead asserts not ahead asserts behind Advanced Constructs
Backreferences \1 match the same text as a previous capturing group. Atomic groups (?>...) prevent backtracking within the group, improving performance and changing semantics. Possessive quantifiers (++, *+, ?+) are shorthand for atomic groups. Named groups (?<name>...) and references \k<name> improve readability. Conditional patterns (?(1)yes|no) match based on group participation. Subroutine calls (?1) reuse a group pattern. These features vary by engine.
- backreference
- Match prior group
- atomic (?>)
- No backtracking
- possessive
- x++ = (?>x+)
\1, \k<name> performance + semantics no giveback