1 Text Processing
1.1 RegExp (Regular Expression) Objects
A RegExp object contains a regular expression and the associated flags.
Note
The form and functionality of regular expressions is modelled after the regular expression facility in the Perl 5 programming language.
1.1.1 Patterns
The RegExp constructor applies the following grammar to the input pattern String. An error occurs if the grammar cannot interpret the String as an expansion of Pattern.
Syntax
Pattern[UnicodeMode, N]::Disjunction[?UnicodeMode, ?N]
Disjunction[UnicodeMode, N]::Alternative[?UnicodeMode, ?N]
Alternative[?UnicodeMode, ?N]|Disjunction[?UnicodeMode, ?N]
Alternative[UnicodeMode, N]::[empty]
Alternative[?UnicodeMode, ?N]Term[?UnicodeMode, ?N]
Term[UnicodeMode, N]::Assertion[?UnicodeMode, ?N]
Atom[?UnicodeMode, ?N]
Atom[?UnicodeMode, ?N]Quantifier
Assertion[UnicodeMode, N]::^
$
\A
\z
\b
\B
(?=Disjunction[?UnicodeMode, ?N])
(?!Disjunction[?UnicodeMode, ?N])
(?<=Disjunction[?UnicodeMode, ?N])
(?<!Disjunction[?UnicodeMode, ?N])
Quantifier::QuantifierPrefix
QuantifierPrefix?
QuantifierPrefix::*
+
?
{DecimalDigits[~Sep]}
{DecimalDigits[~Sep],}
{DecimalDigits[~Sep],DecimalDigits[~Sep]}
Atom[UnicodeMode, N]::PatternCharacter
.
\AtomEscape[?UnicodeMode, ?N]
CharacterClass[?UnicodeMode]
(GroupSpecifier[?UnicodeMode]Disjunction[?UnicodeMode, ?N])
(?:Disjunction[?UnicodeMode, ?N])
SyntaxCharacter::one of^$\.*+?()[]{}|
PatternCharacter::SourceCharacterbut not SyntaxCharacter
AtomEscape[UnicodeMode, N]::DecimalEscape
CharacterClassEscape[?UnicodeMode]
CharacterEscape[?UnicodeMode]
[+N]kGroupName[?UnicodeMode]
CharacterEscape[UnicodeMode]::ControlEscape
cControlLetter
0[lookahead ∉ DecimalDigit]
HexEscapeSequence
RegExpUnicodeEscapeSequence[?UnicodeMode]
IdentityEscape[?UnicodeMode]
ControlEscape::one offnrtv
ControlLetter::one ofabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
GroupSpecifier[UnicodeMode]::[empty]
?GroupName[?UnicodeMode]
GroupName[UnicodeMode]::<RegExpIdentifierName[?UnicodeMode]>
RegExpIdentifierName[UnicodeMode]::RegExpIdentifierStart[?UnicodeMode]
RegExpIdentifierName[?UnicodeMode]RegExpIdentifierPart[?UnicodeMode]
RegExpIdentifierStart[UnicodeMode]::IdentifierStartChar
\RegExpUnicodeEscapeSequence[+UnicodeMode]
[~UnicodeMode]UnicodeLeadSurrogateUnicodeTrailSurrogate
RegExpIdentifierPart[UnicodeMode]::IdentifierPartChar
\RegExpUnicodeEscapeSequence[+UnicodeMode]
[~UnicodeMode]UnicodeLeadSurrogateUnicodeTrailSurrogate
RegExpUnicodeEscapeSequence[UnicodeMode]::[+UnicodeMode]uHexLeadSurrogate\uHexTrailSurrogate
[+UnicodeMode]uHexLeadSurrogate
[+UnicodeMode]uHexTrailSurrogate
[+UnicodeMode]uHexNonSurrogate
[~UnicodeMode]uHex4Digits
[+UnicodeMode]u{CodePoint}
UnicodeLeadSurrogate::any Unicode code point in the inclusive range 0xD800 to 0xDBFF
UnicodeTrailSurrogate::any Unicode code point in the inclusive range 0xDC00 to 0xDFFF
Each \u
HexTrailSurrogate for which the choice of associated u
HexLeadSurrogate is ambiguous shall be associated with the nearest possible u
HexLeadSurrogate that would otherwise have no corresponding \u
HexTrailSurrogate.
HexLeadSurrogate::Hex4Digitsbut only if the MV of Hex4Digits is in the inclusive range 0xD800 to 0xDBFF
HexNonSurrogate::Hex4Digitsbut only if the MV of Hex4Digits is not in the inclusive range 0xD800 to 0xDFFF
IdentityEscape[UnicodeMode]::[+UnicodeMode]SyntaxCharacter
[+UnicodeMode]/
[~UnicodeMode]SourceCharacterbut not UnicodeIDContinue
DecimalEscape::NonZeroDigitDecimalDigits[~Sep]opt[lookahead ∉ DecimalDigit]
CharacterClassEscape[UnicodeMode]::d
D
s
S
w
W
[+UnicodeMode]p{UnicodePropertyValueExpression}
[+UnicodeMode]P{UnicodePropertyValueExpression}
UnicodePropertyValueExpression::UnicodePropertyName=UnicodePropertyValue
LoneUnicodePropertyNameOrValue
UnicodePropertyName::UnicodePropertyNameCharacters
UnicodePropertyNameCharacters::UnicodePropertyNameCharacterUnicodePropertyNameCharactersopt
UnicodePropertyValue::UnicodePropertyValueCharacters
LoneUnicodePropertyNameOrValue::UnicodePropertyValueCharacters
UnicodePropertyValueCharacters::UnicodePropertyValueCharacterUnicodePropertyValueCharactersopt
UnicodePropertyValueCharacter::UnicodePropertyNameCharacter
DecimalDigit
UnicodePropertyNameCharacter::ControlLetter
_
CharacterClass[UnicodeMode]::[[lookahead ≠ ^]ClassRanges[?UnicodeMode]]
[^ClassRanges[?UnicodeMode]]
ClassRanges[UnicodeMode]::[empty]
NonemptyClassRanges[?UnicodeMode]
NonemptyClassRanges[UnicodeMode]::ClassAtom[?UnicodeMode]
ClassAtom[?UnicodeMode]NonemptyClassRangesNoDash[?UnicodeMode]
ClassAtom[?UnicodeMode]-ClassAtom[?UnicodeMode]ClassRanges[?UnicodeMode]
NonemptyClassRangesNoDash[UnicodeMode]::ClassAtom[?UnicodeMode]
ClassAtomNoDash[?UnicodeMode]NonemptyClassRangesNoDash[?UnicodeMode]
ClassAtomNoDash[?UnicodeMode]-ClassAtom[?UnicodeMode]ClassRanges[?UnicodeMode]
ClassAtom[UnicodeMode]::-
ClassAtomNoDash[?UnicodeMode]
ClassAtomNoDash[UnicodeMode]::SourceCharacterbut not one of \ or ] or -
\ClassEscape[?UnicodeMode]
ClassEscape[UnicodeMode]::b
[+UnicodeMode]-
CharacterClassEscape[?UnicodeMode]
CharacterEscape[?UnicodeMode]
Note 1
A number of productions in this section are given alternative definitions in section A.1.1.
Note 2
While the sequence \Z
is already an error when the u
(unicode) flag is present, it is reserved for possible future use as an extension of the \A
and \z
assertions.
1.1.2 Pattern Semantics
1.1.2.1
Runtime Semantics: CompileAssertion
Assertion::\A
- Returns a new Matcher with parameters (x, c) that captures nothing and performs the following steps when called:
- Assert: x is a State.
- Assert: c is a Continuation.
- Let e be x's endIndex.
- If e = 0, return c(x).
- Return failure.
Assertion::\z
- Returns a new Matcher with parameters (x, c) that captures nothing and performs the following steps when called:
- Assert: x is a State.
- Assert: c is a Continuation.
- Let e be x's endIndex.
- If e = InputLength, return c(x).
- Return failure.
B Copyright & Software License
Copyright Notice
© 2022 Ron Buckton, Ecma International
Software License
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.