Readonly
charA super set of the first character.
We can usually only guarantee a super set because lookaround in the pattern may narrow down the actual character set.
Readonly
edgeIf true
, then the first character can be the start/end of the string.
Readonly
exactIf true
, then char
is guaranteed to be exactly the first character and not just a super set of it.
The first character after some point.
This is not constrained to some specific element. This is conceptually how a lookaround sees the input string.
Example
In the regex
/ab?/
the first look character aftera
is{ char: all, edge: true, exact: true }
. It accepts all characters because theb
is optional, so there may be any character aftera
.exact
istrue
because we know that exactly all characters are allowed aftera
.edge
istrue
because the input string is also allowed to just end aftera
(i.e. the string"a"
is accepted).Equivalent regexes
The regex an instance of this type is equivalent to depends only on the
char
andedge
properties. The equivalent regex is:edge: true
:(?=[char]|$)
or(?<=[char]|^)
edge: false
:(?=[char])
or(?<=[char])
(
$
and^
denote the end and start of the input string respectively.)Note that
FirstLookChar
doesn't distinguish between lookaheads and lookbehinds. It can express either.Import values
There are a few important values:
{ char: all, exact: true, edge: true }
is guaranteed to be equivalent to an assertion that accepts all input strings ((?=[\s\S]|$)
).{ char: empty, edge: false }
(exact
doesn't matter) is guaranteed to be equivalent to an assertion that rejects all input strings ((?=[])
).{ char: empty, edge: true }
(exact
doesn't matter) is guaranteed to be equivalent to an edge assertion (either^
or$
).See
FirstLookChars