Moha_regex 1.12.4

An implementation of regular expressions for Rust. This implementation uses finite automata and guarantees linear time matching on all inputs.
Documentation
# NOTE: We define a number of tests where the *match* kind is 'leftmost-first'

# but the *search* kind is 'overlapping'. This is a somewhat nonsensical

# combination and can produce odd results. Nevertheless, those results should

# be consistent so we test them here. (At the time of writing this note, I

# hadn't yet decided whether to make 'leftmost-first' with 'overlapping' result

# in unspecified behavior.)



# This demonstrates how a full overlapping search is obvious quadratic. This

# regex reports a match for every substring in the haystack.

[[test]]

name = "ungreedy-dotstar-matches-everything-100"

regex = [".*?"]

haystack = "zzz"

matches = [

  { id = 0, span = [0, 0] },

  { id = 0, span = [1, 1] },

  { id = 0, span = [0, 1] },

  { id = 0, span = [2, 2] },

  { id = 0, span = [1, 2] },

  { id = 0, span = [0, 2] },

  { id = 0, span = [3, 3] },

  { id = 0, span = [2, 3] },

  { id = 0, span = [1, 3] },

  { id = 0, span = [0, 3] },

]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "greedy-dotstar-matches-everything-100"

regex = [".*"]

haystack = "zzz"

matches = [

  { id = 0, span = [0, 0] },

  { id = 0, span = [1, 1] },

  { id = 0, span = [0, 1] },

  { id = 0, span = [2, 2] },

  { id = 0, span = [1, 2] },

  { id = 0, span = [0, 2] },

  { id = 0, span = [3, 3] },

  { id = 0, span = [2, 3] },

  { id = 0, span = [1, 3] },

  { id = 0, span = [0, 3] },

]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "repetition-plus-leftmost-first-100"

regex = 'a+'

haystack = "aaa"

matches = [[0, 1], [1, 2], [0, 2], [2, 3], [1, 3], [0, 3]]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "repetition-plus-leftmost-first-110"

regex = '☃+'

haystack = "☃☃☃"

matches = [[0, 3], [3, 6], [0, 6], [6, 9], [3, 9], [0, 9]]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "repetition-plus-all-100"

regex = 'a+'

haystack = "aaa"

matches = [[0, 1], [1, 2], [0, 2], [2, 3], [1, 3], [0, 3]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "repetition-plus-all-110"

regex = '☃+'

haystack = "☃☃☃"

matches = [[0, 3], [3, 6], [0, 6], [6, 9], [3, 9], [0, 9]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "repetition-plus-leftmost-first-200"

regex = '(abc)+'

haystack = "zzabcabczzabc"

matches = [

  [[2, 5], [2, 5]],

  [[5, 8], [5, 8]],

  [[2, 8], [5, 8]],

]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "repetition-plus-all-200"

regex = '(abc)+'

haystack = "zzabcabczzabc"

matches = [

  [[2, 5], [2, 5]],

  [[5, 8], [5, 8]],

  [[2, 8], [5, 8]],

  [[10, 13], [10, 13]],

]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "repetition-star-leftmost-first-100"

regex = 'a*'

haystack = "aaa"

matches = [

  [0, 0],

  [1, 1],

  [0, 1],

  [2, 2],

  [1, 2],

  [0, 2],

  [3, 3],

  [2, 3],

  [1, 3],

  [0, 3],

]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "repetition-star-all-100"

regex = 'a*'

haystack = "aaa"

matches = [

  [0, 0],

  [1, 1],

  [0, 1],

  [2, 2],

  [1, 2],

  [0, 2],

  [3, 3],

  [2, 3],

  [1, 3],

  [0, 3],

]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "repetition-star-leftmost-first-200"

regex = '(abc)*'

haystack = "zzabcabczzabc"

matches = [

  [[0, 0], []],

]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "repetition-star-all-200"

regex = '(abc)*'

haystack = "zzabcabczzabc"

matches = [

  [[0, 0], []],

  [[1, 1], []],

  [[2, 2], []],

  [[3, 3], []],

  [[4, 4], []],

  [[5, 5], []],

  [[2, 5], [2, 5]],

  [[6, 6], []],

  [[7, 7], []],

  [[8, 8], []],

  [[5, 8], [5, 8]],

  [[2, 8], [5, 8]],

  [[9, 9], []],

  [[10, 10], []],

  [[11, 11], []],

  [[12, 12], []],

  [[13, 13], []],

  [[10, 13], [10, 13]],

]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "start-end-rep-leftmost-first"

regex = '(^$)*'

haystack = "abc"

matches = [

  [[0, 0], []],

]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "start-end-rep-all"

regex = '(^$)*'

haystack = "abc"

matches = [

  [[0, 0], []],

  [[1, 1], []],

  [[2, 2], []],

  [[3, 3], []],

]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "alt-leftmost-first-100"

regex = 'abc|a'

haystack = "zzabcazzaabc"

matches = [[2, 3], [2, 5]]

match-kind = "leftmost-first"

search-kind = "overlapping"



[[test]]

name = "alt-all-100"

regex = 'abc|a'

haystack = "zzabcazzaabc"

matches = [[2, 3], [2, 5], [5, 6], [8, 9], [9, 10], [9, 12]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "empty-000"

regex = ""

haystack = "abc"

matches = [[0, 0], [1, 1], [2, 2], [3, 3]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "empty-alt-000"

regex = "|b"

haystack = "abc"

matches = [[0, 0], [1, 1], [2, 2], [1, 2], [3, 3]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "empty-alt-010"

regex = "b|"

haystack = "abc"

matches = [[0, 0], [1, 1], [2, 2], [1, 2], [3, 3]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

# See: https://github.com/rust-lang/regex/issues/484

name = "iter1-bytes"

regex = ''

haystack = ""

matches = [[0, 0], [1, 1], [2, 2], [3, 3]]

utf8 = false

match-kind = "all"

search-kind = "overlapping"



[[test]]

# See: https://github.com/rust-lang/regex/issues/484

name = "iter1-utf8"

regex = ''

haystack = ""

matches = [[0, 0], [3, 3]]

match-kind = "all"

search-kind = "overlapping"



[[test]]

name = "iter1-incomplete-utf8"

regex = ''

haystack = '\xE2\x98'  # incomplete snowman

matches = [[0, 0], [1, 1], [2, 2]]

match-kind = "all"

search-kind = "overlapping"

unescape = true

utf8 = false



[[test]]

name = "scratch"

regex = ['sam', 'samwise']

haystack = "samwise"

matches = [

  { id = 0, span = [0, 3] },

]

match-kind = "leftmost-first"

search-kind = "overlapping"