Skip to main content
Module

x/leac/mod.ts>RegexRule

Lexer / tokenizer
Latest
interface RegexRule
implements Rule
import { type RegexRule } from "https://deno.land/x/leac@v0.6.0/mod.ts";

Regex rule - looks for a regular expression match.

Properties

regex: RegExp

Regular expression to match.

  • Can't have the global flag.

  • All regular expressions are used as sticky, you don't have to specify the sticky flag.

  • Empty matches are considered as non-matches - no token will be emitted in that case.

optional
replace: string

Replacement string can include patterns, the same as String.prototype.replace().

This will only affect the text property of an output token, not it's offset or length.

Note: the regex has to be able to match the matched substring when taken out of context in order for replace to work - boundary/neighborhood conditions may prevent this.