Engine: Oniguruma
Home | Engines | Reference | Improve this section
Languages
Features
The following features are supported:
- ✔ Flags
- ✔ Anchors
- ✔ Buffer Boundaries
- ✔ Word Boundaries
- ✔ Text Segment Boundaries
- ✔ Continuation Escape
- ✔ Alternatives
- ✔ Wildcard
- ✔ Character Classes
- ✔ Posix Character Classes
- ✔ Negated Posix Character Classes
- ✔ Character Class Escapes
- ✔ Line Endings Escape
- ✔ Character Property Escapes
- ✔ Character Class Nested Set
- ✔ Character Class Intersection
- ✔ Character Class Subtraction
- ✔ Quantifiers
- ✔ Lazy Quantifiers
- ✔ Possessive Quantifiers
- ✔ Capturing Groups
- ✔ Named Capturing Groups
- ✔ Non-Capturing Groups
- ✔ Backreferences
- ✔ Comments
- ✔ Modifiers
- ✔ Lookahead
- ✔ Lookbehind
- ✔ Non-Backtracking Expressions
- ✔ Recursion
- ✔ Conditional Expressions
- ✔ Subroutines
- ✔ Callouts
The following features are not supported:
- ❌ Collating Elements
- ❌ Equivalence Classes
- ❌ Character Class Union
- ❌ Character Class Symmetric Difference
- ❌ Character Class Complement
- ❌ Quoted Characters
- ❌ Line Comments
- ❌ Branch Reset
- ❌ Backtracking Control Verbs
Feature: Flags
Main article | Reference | Back to top | Improve this section: 1, 2
Flags control certain aspects of the matching behavior of a pattern.
Syntax
The following flags are supported:
i
— Ignore Case. Matches character classes using a case-insensitive comparison.x
— Extended Mode. Ignores whitespace in a pattern. Spaces must instead be represented by\s
or\
(an escaped space).W
— ASCII-only words (when using\w
,\p{Word}
,[[:word:]]
,\b
, or\B
)D
— ASCII-only digits (when using\d
,\p{Digit}
,[[:digit:]]
)S
— ASCII-only space (when using\s
,\p{Space}
,[[:space:]]
)P
— ASCII-only POSIX properties (includesW
,D
, andS
flags)y{?}
— Changes meaning of\X
,\y
, and\Y
in unicode mode:y{g}
— Extended Grapheme Cluster modey{w}
— Word mode.
Some flags depend on options provided to Oniguruma reference:
ONIG_SYNTAX_ONIGURUMA
:m
— Multiline. Causes the wildcard.
to match newline characters.
ONIG_SYNTAX_PERL
andONIG_SYNTAX_JAVA
:
See Also
Feature: Anchors
Main article | Reference | Back to top | Improve this section: 1, 2
Anchors match the start or end of a line.
Syntax
^
— Matches the start of a line when them
(multiline) flag is set. Otherwise, matches the start of the input.$
— Matches the end of a line when them
(multiline) flag is set. Otherwise, matches the end of the input.
See Also
Feature: Buffer Boundaries
Main article | Reference | Back to top | Improve this section: 1, 2
A Buffer Boundary is an Atom that matches the start or the end of the input. This differs slightly from ^
and $
which can be affected by RegExp flags like m
.
Syntax
\A
— Matches the start of the input.\z
— Matches the end of the input.\Z
— A zero-width assertion consisting of an optional newline at the end of the buffer. Equivalent to(?=\n?\z)
.
See Also
Feature: Word Boundaries
Main article | Reference | Back to top | Improve this section: 1, 2
A Word Boundary is an Atom that matches the start or the end of a word.
Syntax
\b
— Matches the start or the end of a word.\B
— Matches when not at the start or the end of a word.
See Also
Feature: Text Segment Boundaries
Main article | Reference | Back to top | Improve this section: 1, 2
A Text Segment Boundary is an Atom that matches the start or the end of a text segment.
Syntax
\y
— Matches the start or the end of a text segment.\Y
— Matches when not at the start or the end of a text segment.
See Also
Feature: Continuation Escape
Main article | Reference | Back to top | Improve this section: 1, 2
A Continuation Escape is a zero-width assertion that matches either the start of the input or the start of the last match.
Syntax
\G
— Matches either the start of the input or the start of the last match.
See Also
Feature: Alternatives
Main article | Reference | Back to top | Improve this section: 1, 2
An Alternative represents two or more branches in a pattern. If first branch of a pattern fails to match, each alternative is attempted from left to right until a match is found.
Syntax
…|…
— Matches the pattern to the left of the|
. If that fails, matches the pattern to the right of|
.
Feature: Wildcard
Main article | Reference | Back to top | Improve this section: 1, 2
A Wildcard matches a single, non-newline character.
Syntax
.
— Matches any character except newline characters. If them
flag is set then this matches any character.- NOTE: The
m
-flag in Oniguruma is equivalent to thes
-flag (i.e., dot all) in Perl, ECMAScript, .NET, etc.
- NOTE: The
Feature: Character Classes
Main article | Reference | Back to top | Improve this section: 1, 2
A Character Class is an Atom that specifies a set of characters to match a single character in the set.
Syntax
[…]
— Where…
is one or more single characters or character class escapes, excluding^
at the start and-
between two entries in the set. Matches a character in the set. Example:[abc]
matchesa
,b
, orc
.[^…]
— Where…
is one or more single characters or character class escapes, excluding-
between two entries in the set. Matches any character not in the set. Example:[^abc]
matchesd
,e
, orf
, etc., but nota
,b
, orc
.[a-z]
— Where a and z are single characters or character escapes. Matches any character in the range between a and z (inclusive). Example:[a-c]
matchesa
,b
, orc
, but notd
.
See Also
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Posix Character Classes
Main article | Reference | Back to top | Improve this section: 1, 2
A Posix Character Class is a member of a Character Class set that specifies a named, pre-defined set of characters.
Syntax
[[:name:]]
— Where name is in a set of predefined names. Matches any character in the set.
See Also
- Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Negated Posix Character Classes
Main article | Reference | Back to top | Improve this section: 1, 2
A Negated Posix Character Class is a member of a Character Class set that specifies a named, pre-defined set of excluded characters.
Syntax
[[:^name:]]
— Where name is in a set of predefined names. Matches any character not in the set.
See Also
- Character Classes
- Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Collating Elements
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Equivalence Classes
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Escapes
Main article | Reference | Back to top | Improve this section: 1, 2
A Character Class Escape is a single character escape that represents an entire character class. They can be used as an element of a Character Class or as an Atom. It is often the case that a lower-case escape character is the inclusive set, while an upper-case variant of the same character excludes that set.
Syntax
\d
— A digit character.- Non-unicode mode: Equivalent to
[0-9]
. - Unicode mode: Equivalent to
\p{General_Category=Decimal_Number}
- Non-unicode mode: Equivalent to
\D
— Any non-digit character.- Non-unicode mode: Equivalent to
[^0-9]
. - Unicode mode: Equivalent to
\P{General_Category=Decimal_Number}
- Non-unicode mode: Equivalent to
\h
— Any hexadecimal digit character. Equivalent to[0-9a-fA-F]
.\H
— Any non-hexadecimal character. Equivalent to[^0-9a-fA-F]
.\w
— Any “word” character.- Non-unicode mode: Equivalent to
[a-zA-Z0-9_]
. - Unicode mode: Any character in the following General_Category sets: Letter, Mark, Number, Connector_Punctuation
- Non-unicode mode: Equivalent to
\W
— Any non-“word” character.- Non-unicode mode: Equivalent to
[^a-zA-Z0-9_]
. - Unicode mode: Any character not in the following General_Category sets: Letter, Mark, Number, Connector_Punctuation
- Non-unicode mode: Equivalent to
\s
— Any whitespace character.- Non-unicode mode: Any character in the set
\t
,\n
,\v
,\f
,\r
,\x20
. - Unicode mode: Any character in the set
U+0009
,U+000A
,U+000B
,U+000C
,U+000D
,U+0085
, or the following General_Category sets: Line_Separator, Paragraph_Separator, Space_Separator
- Non-unicode mode: Any character in the set
\S
— Any non-whitespace character.- Non-unicode mode: Any character not in the set
\t
,\n
,\v
,\f
,\r
,\x20
. - Unicode mode: Any character not in the set
U+0009
,U+000A
,U+000B
,U+000C
,U+000D
,U+0085
, or the following General_Category sets: Line_Separator, Paragraph_Separator, Space_Separator
- Non-unicode mode: Any character not in the set
\N
— Any non-newline character. Equivalent to(?-m:.)
.- NOTE: The
m
-flag in Oniguruma is equivalent to thes
-flag (i.e., dot all) in Perl, ECMAScript, .NET, etc.
- NOTE: The
\O
— Any character. Equivalent to(?m:.)
.- NOTE: The
m
-flag in Oniguruma is equivalent to thes
-flag (i.e., dot all) in Perl, ECMAScript, .NET, etc.
- NOTE: The
\X
— Text segment. Equivalent to(?>\O(?:\Y\O)*)
.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Line Endings Escape
Main article | Reference | Back to top | Improve this section: 1, 2
A Line Endings Escape is an Atom that matches any line ending character sequence.
Syntax
\R
— Equivalent to(?>\r\n?|[\x0A-\x0C\x85\u{2028}\u{2029}])
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Property Escapes
Main article | Reference | Back to top | Improve this section: 1, 2
A Character Property Escape is an escape sequence used to match a character with a specific character property.
Syntax
\p{name}
— Where name is a predefined property name. Matches a character that has the property name.\p{^name}
— Where name is a predefined property name. Matches a character that does not have the property name.\P{name}
— Where name is a predefined property name. Matches a character that does not have the property name.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Nested Set
Main article | Reference | Back to top | Improve this section: 1, 2
A Character Class Nested Set allows you to to define a nested character class inside of a character class.
Syntax
[[…]]
— Matches any character in the set, just like a normal character class.[[^…]]
— Where…
is one or more single characters or character class escapes, excluding-
between two entries in the set. Matches any character not in the set, just like a normal [negated character class].[[a-z]]
— Where a and z are single characters or character escapes. Matches any character in the range between a and z (inclusive), just like a normal [character class range].
Example
[a-z&&[^d-q]]
Is equivalent to:
[a-cr-z]
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Intersection
Main article | Reference | Back to top | Improve this section: 1, 2
Character Class Intersection allows you to indicate that only characters that are in both character classes should match.
Syntax
[…&&…]
— Matches any character that is in both the left- and right-hand sets of&&
.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Union
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Subtraction
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Subtraction
Main article | Reference | Back to top | Improve this section: 1, 2
Character Class Subtraction allows you to exclude a class of characters from another class of characters in a character class.
NOTE: Oniguruma does not support character class subtraction directly, instead you must use a combination of character class intersections and character class nested sets
Example
[a-w&&[^c-g]z]
Is equivalent to the following pseudo pattern:
([a-w] AND ([^c-g] OR z))
Which reduces to:
[abh-w]
Source for this example comes from Oniguruma: source
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Symmetric Difference
- Character Class Complement
Feature: Character Class Symmetric Difference
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Complement
Feature: Character Class Complement
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
See Also
- Character Classes
- Posix Character Classes
- Negated Posix Character Classes
- Collating Elements
- Equivalence Classes
- Character Class Escapes
- Line Endings Escape
- Character Property Escapes
- Character Class Nested Set
- Character Class Intersection
- Character Class Union
- Character Class Subtraction
- Character Class Symmetric Difference
Feature: Quoted Characters
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
Feature: Quantifiers
Main article | Reference | Back to top | Improve this section: 1, 2
Quantifiers specify repetition of an Atom. By default, quantifiers are “greedy” in that they attempt to match as many instances of the preceding Atom as possible to satisfy the pattern before backtracking.
Syntax
*
— Matches the preceding Atom zero or more times. Example:a*b
matchesb
,ab
,aab
,aaab
, etc.+
— Matches the preceding Atom one or more times. Example:a+b
matchesab
,aab
,aaab
, etc., but notb
.?
— Matches the preceding Atom zero or one times. Example:a?b
matchesb
,ab
.{n}
— Where n is an integer. Matches the preceding Atom exactly n times. Example:a{2}
matchesaa
but nota
oraaa
.{n,}
— Where n is an integer. Matches the preceding Atom at-least n times. Example:a{2,}
matchesaa
,aaa
,aaaa
, etc., but nota
.{n,m}
— Where n and m are integers, and m >= n. Matches the preceding Atom at-least n times and at-most m times. Example:a{2,3}
matchesaa
,aaa
,aaaa
, etc., but nota
oraaaa
.
See Also
Feature: Lazy Quantifiers
Main article | Reference | Back to top | Improve this section: 1, 2
Lazy Quantifiers specify repetition of an Atom, but attempt to match as few instances of the preceding Atom as possible to satisfy the pattern before advancing.
Syntax
*?
— Matches the preceding Atom zero or more times.+?
— Matches the preceding Atom one or more times.??
— Matches the preceding Atom zero or one times.{n}?
— Where n is an integer. Matches the preceding Atom exactly n times.{n,}?
— Where n is an integer. Matches the preceding Atom at-least n times.{n,m}?
— Where n and m are integers, and m >= n. Matches the preceding Atom at-least n times and at-most m times.
See Also
Feature: Possessive Quantifiers
Main article | Reference | Back to top | Improve this section: 1, 2
Possessive Quantifiers are like greedy (i.e., regular) quantifiers, except that backtracking is not performed.
Syntax
*+
— Match zero or more characters without backtracking.++
— Match one or more characters without backtracking.?+
— Match zero or one characters without backtracking.{n,}+
— Where n is an integer. Matches the preceding Atom at-least n times without backtracking.{n,m}+
— Where n and m are integers, and m >= n. Matches the preceding Atom at-least n times and at-most m times without backtracking.
See Also
Feature: Capturing Groups
Main article | Reference | Back to top | Improve this section: 1, 2
A Capturing Group is a subexpression that can be treated as an Atom and can be repeated using Quantifiers and referenced using Backreferences by index. A Capturing Group can be captured and returned by the matching algorithm.
Syntax
(…)
— Groups the subexpression as a single Atom. The result is captured and returned by the matching algorithm.
See Also
Feature: Named Capturing Groups
Main article | Reference | Back to top | Improve this section: 1, 2
A Named Capturing Group is a subexpression that can be captured and returned by the matching algorithm. A Named Capturing Group is also an Atom and can be repeated using Quantifiers and referenced using Backreferences by name.
Syntax
(?<name>…)
— Groups the subexpression as a single Atom associated with the provided name. The result is captured and returned by the matching algorithm.(?'name'…)
— Groups the subexpression as a single Atom associated with the provided name. The result is captured and returned by the matching algorithm.
See Also
Feature: Non-Capturing Groups
Main article | Reference | Back to top | Improve this section: 1, 2
A Non-capturing Group is a subexpression that can be treated as an Atom and can be repeated using Quantifiers but cannot be referenced using Backreferences. A Non-capturing Group is not captured by the matching algorithm.
Syntax
(?:…)
— Groups the subexpression as a single Atom.
See Also
Feature: Backreferences
Main article | Reference | Back to top | Improve this section: 1, 2
Backreferences allow a pattern to re-match a previously matched capture group1 2 either by number (n) or by name.
Syntax
\n
— Where n is a decimal digit in the range 1-9. Matches the same string as the capture group n.\k<n>
— Where n is an integer > 0. Matches the same string as the capture group n.\k'n'
— Where n is an integer > 0. Matches the same string as the capture group n.\k<-n>
— Where n is an integer > 0. Matches the nth previous capture group.\k'-n'
— Where n is an integer > 0. Matches the nth previous capture group.\k<+n>
— Where n is an integer > 0. Matches the nth next capture group.\k'+n'
— Where n is an integer > 0. Matches the nth next capture group.\k<name>
— Matches the same string as the named capture group with the name name.\k'name'
— Matches the same string as the named capture group with the name name.
See Also
Feature: Comments
Main article | Reference | Back to top | Improve this section: 1, 2
A Comment is a sequence of characters that is ignored by pattern matching and can be used to document a pattern.
Syntax
(?#…)
— The entire expression is removed from the pattern. A comment may not contain other(
or)
characters.
See Also
Feature: Line Comments
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
See Also
Feature: Modifiers
Main article | Reference | Back to top | Improve this section: 1, 2
Modifiers allow you to change the currently active RegExp flags within a subexpression.
Syntax
(?imxWDSPy-imxWDSPy)
- Sets or unsets (using-
) the specified RegExp flags starting at the current position until the next closing)
or the end of the pattern. Example:(?-i)A(?i)B(?-i)C
matchesABC
,AbC
.- NOTE: When option
ONIG_SYNTAX_ONIGURUMA
is specified, them
-flag in Oniguruma is equivalent to thes
-flag (i.e., dot all) in Perl, ECMAScript, .NET, etc. reference - NOTE: When option
ONIG_SYNTAX_PERL
orONIG_SYNTAX_JAVA
are specified, them
ands
flags are equivalent to their Perl/Java counterparts. reference
- NOTE: When option
(?imxWDSPy-imxWDSPy:…)
- Sets or unsets (using-
) the specified RegExp flags for the subexpression. Example:(?-i:A(?i:B)C)
matchesABC
,AbC
.- NOTE: When option
ONIG_SYNTAX_ONIGURUMA
is specified, them
-flag in Oniguruma is equivalent to thes
-flag (i.e., dot all) in Perl, ECMAScript, .NET, etc. reference - NOTE: When option
ONIG_SYNTAX_PERL
orONIG_SYNTAX_JAVA
are specified, them
ands
flags are equivalent to their Perl/Java counterparts. reference
- NOTE: When option
See Also
Feature: Branch Reset
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.
Feature: Lookahead
Main article | Reference | Back to top | Improve this section: 1, 2
A Lookahead is a zero-width assertion that matches if the provided pattern would match the characters to the right of the current position.
Syntax
(?=…)
— Positive Lookahead. Matches if the provided pattern would match but does not advance the current position.(?!…)
— Negative Lookahead. Matches if the provided pattern would not match, but does not advance the current position.
See Also
Feature: Lookbehind
Main article | Reference | Back to top | Improve this section: 1, 2
A Lookbehind is a zero-width assertion that matches if the provided pattern would match the characters to the left of the current position.
Syntax
(?<=…)
— Positive Lookbehind. Matches if the provided pattern would match the preceding characters, but does not advance the current position. The pattern must have a fixed length (unbounded quantifiers are not permitted).(?<!…)
— Negative Lookbehind. Matches if the provided pattern would not match the preceding characters, but does not advance the current position. The pattern must have a fixed length (unbounded quantifiers are not permitted).
See Also
Feature: Non-Backtracking Expressions
Main article | Reference | Back to top | Improve this section: 1, 2
A Non-Backtracking Expression is matched independent of neighboring patterns, and will not backtrack in the event of a failed match. This is often used to improve performance.
Syntax
(?>…)
— Matches the provided pattern, but no backtracking is performed if the match fails.
Feature: Recursion
Main article | Reference | Back to top | Improve this section: 1, 2
A Recursive Expression provides a mechanism for re-evaluating a capture group inside of itself, to handle cases such as matching balanced parenthesis or brackets, etc.
Syntax
\k<n+n>
— Where n is an integer >= 1 and level is an integer >= 0. Matches the same string as the capture group n at the recursion level relative to the referenced capture group.\k'n+n'
— Where n is an integer >= 1 and level is an integer >= 0. Matches the same string as the capture group n at the recursion level relative to the referenced capture group.\k<n-n>
— Where n is an integer >= 1 and level is an integer >= 0. Matches the same string as the capture group n at the recursion level relative to the referenced capture group.\k'n-n'
— Where n is an integer >= 1 and level is an integer >= 0. Matches the same string as the capture group n at the recursion level relative to the referenced capture group.\k<name>
— Where level is an integer >= 0. Matches the same string as the named capture group with the name name at the recursion level relative to the referenced named capture group.\k'name'
— Where level is an integer >= 0. Matches the same string as the named capture group with the name name at the recursion level relative to the referenced named capture group.\g<n>
— Where n is an integer >= 1. Evaluates the capture group whose offset is n.\g'n'
— Where n is an integer >= 1. Evaluates the capture group whose offset is n.\g<0>
— Evaluates the entire pattern at the current position.\g'0'
— Evaluates the entire pattern at the current position.\g<-n>
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the left of the current Atom.\g'-n'
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the left of the current Atom.\g<+n>
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the right of the current Atom.\g'+n'
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the right of the current Atom.\g<name>
— Evaluates the named capture group with the provided name.\g'name'
— Evaluates the named capture group with the provided name.
NOTE: Left-most recursive calls are forbidden:
(?<name>a|\g<name>b)
- error(?<name>a|b\g<name>c)
- okSource for this example comes from Oniguruma: source
Feature: Conditional Expressions
Main article | Reference | Back to top | Improve this section: 1, 2
A Conditional Expression checks a condition and evaluates its first alternative if the condition is true; otherwise, it evaluates its second alternative.
Syntax
(?(condition)condition|condition)
— Matches yes-pattern if condition is true; otherwise, matches no-pattern.(?(condition)condition)
— Matches yes-pattern if condition is true; otherwise, matches the empty string.
Conditions
The following conditions are supported:
(?(?=test-pattern)…)
— Evaluates to true if a lookahead for test-pattern matches; otherwise, evaluates to false.(?(?!test-pattern)…)
— Evaluates to true if a negative lookahead for test-pattern matches; otherwise, evaluates to false.(?(n)…)
— Evaluates to true if the capture group at offset n was successfully matched; otherwise, evaluates to false.(?(-n)…)
— Evaluates to true if the nth capture group declared to the left of the current Atom was successfully matched; otherwise, evaluates to false.(?(+n)…)
— Evaluates to true if the nth capture group declared to the right of the current Atom was successfully matched; otherwise, evaluates to false.(?(n-n)…)
— Evaluates to true if the capture group at offset n was successfully matched at the recursion level relative to the referenced capture group; otherwise, evaluates to false.(?(n+n)…)
— Evaluates to true if the capture group at offset n was successfully matched at the recursion level relative to the referenced capture group; otherwise, evaluates to false.(?(<name>)…)
— Evaluates to true if the named capture group with the name name was successfully matched; otherwise, evaluates to false.(?('name')…)
— Evaluates to true if the named capture group with the name name was successfully matched; otherwise, evaluates to false.(?(<name-name>)…)
— Evaluates to true if the named capture group with the name name was successfully matched at the recursion level relative to the referenced capture group; otherwise, evaluates to false.(?('name-name')…)
— Evaluates to true if the named capture group with the name name was successfully matched at the recursion level relative to the referenced capture group; otherwise, evaluates to false.(?(<name+name>)…)
— Evaluates to true if the named capture group with the name name was successfully matched at the recursion level relative to the referenced capture group; otherwise, evaluates to false.(?('name+name')…)
— Evaluates to true if the named capture group with the name name was successfully matched at the recursion level relative to the referenced capture group; otherwise, evaluates to false.
Feature: Subroutines
Main article | Reference | Back to top | Improve this section: 1, 2
A Subroutine is a pre-defined capture group or named capture group that can be reused in multiple places within the pattern to re-evaluate the subexpression from the group.
Syntax
\g<n>
— Where n is an integer >= 1. Evaluates the capture group whose offset is n.\g'n'
— Where n is an integer >= 1. Evaluates the capture group whose offset is n.\g<0>
— Evaluates the entire pattern at the current position.\g'0'
— Evaluates the entire pattern at the current position.\g<-n>
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the left of the current Atom.\g'-n'
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the left of the current Atom.\g<+n>
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the right of the current Atom.\g'+n'
— Where n is an integer >= 1. Evaluates the capture group whose offset is the nth capture group declared to the right of the current Atom.\g<name>
— Evaluates the named capture group with the provided name.\g'name'
— Evaluates the named capture group with the provided name.
Example
(?(DEFINE)
(?<Year>\d{4}|[+-]\d{5,})
(?<Month>0[1-9]|1[0-2])
(?<Day>0[1-9]|2[0-9]|3[01])
)
(?<Date>(?&Year)-(?&Month)-(?&Day)|(?&Year)(?&Month)(?&Day))
Feature: Callouts
Main article | Reference | Back to top | Improve this section: 1, 2
A Callout is a user-defined function that can be evaluated while matching.
Syntax
- Callouts of contents:
(?{…contents…})
— Invokes the callout with the provided contents.(?{…contents…}D)
— Invokes the callout with the provided contents and direction flag character D. The direction flag must be one of:X
— Invoked while progressing and retracting.<
— Invoked while retracting.>
— Invoked while progressing.
(?{…contents…}[tag])
— Invokes the callout with the provided contents and tag.(?{…contents…}[tag]D)
— Invokes the callout with the provided contents, tag, and direction flag character D. The direction flag must be one of:X
— Invoked while progressing and retracting.<
— Invoked while retracting.>
— Invoked while progressing.
- Callouts of name:
(*name)
— Invokes the callout with the provided name.(*name{args…})
— Invokes the callout with the provided name and args.(*name[tag])
— Invokes the callout with the provided name and tag.(*name[tag]{args…})
— Invokes the callout with the provided name, tag, and args.
Feature: Backtracking Control Verbs
Main article | Back to top | Improve this section: 1, 2
❌ This feature is not supported.