Interface FirstLookChar

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 after a is { char: all, edge: true, exact: true }. It accepts all characters because the b is optional, so there may be any character after a. exact is true because we know that exactly all characters are allowed after a. edge is true because the input string is also allowed to just end after a (i.e. the string "a" is accepted).

Equivalent regexes

The regex an instance of this type is equivalent to depends only on the char and edge 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:

  • Accept all: The instance { char: all, exact: true, edge: true } is guaranteed to be equivalent to an assertion that accepts all input strings ((?=[\s\S]|$)).
  • Reject all: The instance { char: empty, edge: false } (exact doesn't matter) is guaranteed to be equivalent to an assertion that rejects all input strings ((?=[])).
  • Edge assertion: The instance { char: empty, edge: true } (exact doesn't matter) is guaranteed to be equivalent to an edge assertion (either ^ or $).

Hierarchy

  • FirstLookChar

Properties

Properties

char: CharSet

A 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.

edge: boolean

If true, then the first character can be the start/end of the string.

exact: boolean

If true, then char is guaranteed to be exactly the first character and not just a super set of it.