regex自始可用
A regular expression.
Can be used as a show rule selector or with string methods.
Visit this website for a complete specification of the supported syntax.
With string methods
Regular expressions can be used with string methods like find, split, replace, match, or matches. See the documentation of these methods for more details.
#"a,b;c".split(regex("[,;]"))

With show rules
Regular expressions can also be used with show rules to match on and transform text in the document. For example, below, we are turning all numbers red.
#show regex("\\d+"): set text(red)
The numbers 1 to 10.

Sometimes, you may also want to combine both uses, by first matching on text with a show rule and then rematching on the text to extract a specific capture group. In this case, it can be convenient to store the regular expression in a variable instead of repeating it twice.
#let pattern = regex("\|([^|]*)\|")
#show pattern: it => {
let m = it.text.match(pattern)
let inner = m.captures.first()
highlight(inner)
}
A |handy-dandy| highlighter!

构造函数自始可用
Create a regular expression from a string.
regex
The regular expression as a string.
Both Typst strings and regular expressions use backslashes for escaping. To produce a regex escape sequence that is also valid in Typst, you need to escape the backslash itself (e.g., writing regex("\\\\") for the regex \\). Regex escape sequences that are not valid Typst escape sequences (e.g., \d and \b) can be entered into strings directly, but it’s good practice to still escape them to avoid ambiguity (i.e., regex("\\b\\d")). See the list of valid string escape sequences.
If you need many escape sequences, you can also create a raw element and extract its text to use it for your regular expressions: regex(`\d+\.\d+\.\d+`.text).