

\g where “name” is the name of a capturing groupĪ (? b \g ? y ) z matches abyz, abbyyz, abbbyyyz, etc. (?P>name) where “name” is the name of a capturing groupĪ (?P b (?P>x) ? y ) z matches abyz, abbyyz, abbbyyyz, etc. (?&name) where “name” is the name of a capturing groupĪ (? b (?&x) ? y ) z matches abyz, abbyyz, abbbyyyz, etc. \g'+1' x ( ) matches axa, axb, bxa, and bxb (?+1) x ( ) matches axa, axb, bxa, and bxb Recursion of or subroutine call to a capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from left to right starting at the subroutine call. Recursion of or subroutine call to a capturing group that can be found by counting as many opening parentheses of named or numbered capturing groups as specified by the number from right to left starting at the subroutine call.Ī ( b (?-1) ? y ) z matches abyz, abbyyz, abbbyyyz, etc.Ī ( b \g'-1' ? y ) z matches abyz, abbyyz, abbbyyyz, etc. \g'1' where 1 is the number of a capturing groupĪ ( b \g'1' ? y ) z matches abyz, abbyyz, abbbyyyz, etc. \g where 1 is the number of a capturing groupĪ ( b \g ? y ) z matches abyz, abbyyz, abbbyyyz, etc. Recursion of a capturing group or subroutine call to a capturing group.Ī ( b (?1) ? y ) z matches abyz, abbyyz, abbbyyyz, etc. (?1) where 1 is the number of a capturing group Recursion of the entire regular expression.Ī (?R) ? z matches az, aazz, aaazzz, etc.Ī (?0) ? z matches az, aazz, aaazzz, etc.Ī \g'0' ? z matches az, aazz, aaazzz, etc. (?'capture-subtract'regex) where “capture” and “subtract” are group names and “regex” is any regex (?(l) (?!) ) $ matches any palindrome word If the group “subtract” has no matches to subtract, then the balancing group fails to match, regardless of whether “regex” is specified or not. If “regex” is omitted, the balancing group succeeds without advancing through the string. If “capture” is omitted, the same happens without storing the match. If this group has captured matches that haven’t been subtracted yet, then the balancing group subtracts one capture from “subtract”, attempts to match “regex”, and stores its match into the group “capture”. The name “subtract” must be used as the name of a capturing group elsewhere in the regex. (?regex) where “capture” and “subtract” are group names and “regex” is any regex Regex Reference: Balancing Groups, Recursion, and Subroutines
