/regexp

A regular expression module for MoonBit

Primary LanguageMoonBitApache License 2.0Apache-2.0

RegExp

check

A regular expression module based on a backtracking engine. Due to backtracking during matching, some regular expressions will run for a long time under specific inputs, also known as catastrophic backtracking. The design of the bytecode and interpreter was heavily inspired by the .NET regular expression library.

Usage

let regexp = @regexp.compile!("^(?<addr>[a-zA-Z0-9._%+-]+)@(?<host>[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$")
let match_result = regexp.matches("12345@test.com")
println(match_result.success()) // true
println(match_result.captures()) // ["12345@test.com", "12345", "test.com"]
println(match_result.named_captures()) // {"addr": "12345", "host": "test.com"}

Features

Character classes

  • Character range
  • Escapes (e.g. \d, \D, \s, \S, \w, \W)

Assertions

  • Begin of input
  • End of input
  • Word boundary
  • Lookaround

Groups

  • Capturing group
  • Non-capturing group
  • Named capturing group

Backreferences

  • Group backreference
  • Named backreference

Quantifiers

  • Zero or more (*)
  • Zero or one (?)
  • One or more (+)
  • Range ({n}, {n,}, {n, m})
  • Non-greedy

Encodings

  • Unicode