Module fixed_offset

Module fixed_offset 

Source
Expand description

This is a highly-efficient implementation for regexes where capture groups always have the same offset and the same length (in bytes). This also means the text has a fixed length.

This means that no variable quantifiers are allowed, and alternations must have the same length in each case. Additionally, capture groups cannot occur within alternations.

The strategy is essentially to only ever run test then to index fixed offsets

ยงExamples

  • ^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$ for hex colors
  • ^\+1 ([0-9]{3})-([0-9]{3})-([0-9]{4})$ for US phone numbers