mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
1cfa153ff3
implement a lightweight NFA-based regular expression engine for mruby:
engine (src/re_compile.c, src/re_exec.c, src/re_utf8.c):
- Pike VM (Thompson NFA simulation) with O(n*m) time guarantee
- ReDoS-resistant by design (no backtracking for basic patterns)
- supports: literals, ., *, +, ?, {n,m}, [], [^], |, ()
- character classes: \d, \w, \s and negations
- anchors: ^, $, \A, \z, \Z, \b, \B
- flags: i (ignorecase), m (multiline/dotall)
- captures with MatchData
Ruby API (src/regexp.c, mrblib/string_regexp.rb):
- Regexp.new, #match, #match?, #=~, #===, #source, #inspect
- Regexp.escape, Regexp::IGNORECASE/MULTILINE constants
- MatchData#[], #captures, #to_a, #begin, #end, #pre_match, #post_match
- String#match, #match?, #=~, #sub, #gsub, #scan, #split
~1700 lines of C + ~120 lines of Ruby. no external dependencies.
Co-authored-by: Claude <noreply@anthropic.com>
8 lines
244 B
Ruby
8 lines
244 B
Ruby
MRuby::Gem::Specification.new('mruby-regexp') do |spec|
|
|
spec.license = 'MIT'
|
|
spec.authors = 'mruby developers'
|
|
spec.summary = 'Regexp class (built-in NFA engine)'
|
|
|
|
spec.add_dependency 'mruby-string-ext', :core => 'mruby-string-ext'
|
|
end
|