Watch it decide.

The first one is live and yours to drive: the pattern you type runs through moonregex itself, compiled to JavaScript, and answers in the browser. The rest step through output the library gave earlier.

01Your pattern, your text

engine loads when this is in view

02A match, step by step

(?P<w>\w+)\s+\1 over go go no

python · 1 match

A backreference makes the pattern say “the same word twice”. The engine records the group, then asks it back.

0Press step to watch the engine work.
group w \s+ \1

03One pattern, three spellings

a date, written three ways

same answer

The same (?<year>\d{4})-(?<month>\d{2}), written for Python's grammar, for the lexmatch grammar the core library speaks, and assembled from the combinators.

04Escape, three ways

the same string, escaped for three grammars

recorded

Escaping depends on what the grammar treats as special, so escape takes a dialect. Pick a string to compare.

05Grapheme clusters

\X over é👨‍👩‍👧🇯🇵

3 clusters, 9 code points

A letter with its accent, a family joined by zero-width joiners, and a flag — each one cluster, whatever it costs in code points.

06What lowers onto the core engine

Pattern::lower

10 patterns

A pattern the core engine can run is handed to it as a @string.Regex. The rest stay here — that is the line between the two engines.

lowers → @string.Regex

  • abc
  • a(b+)c
  • [a-z]+
  • (?<y>\d{4})

stays here

  • \bab\b
  • ^ab$
  • (a)\1
  • a(?=b)
  • \X
  • (?>ab)

\bab\b and ^ab$ are the two that surprise people: the core engine's word boundary is ASCII, and its $ does not sit before a trailing newline, so neither is the same assertion this library means.

Next: the guide →