Skip to content

Conversation

@san-rizz-777
Copy link
Member

@san-rizz-777 san-rizz-777 commented Feb 2, 2026

Add regex matching functions similar to Python's re module

Overview

This PR adds core regex matching functionality to the NFA matcher, providing a Python re-like interface for pattern matching operations.

Changes

match(const std::string_view &text)

  • Performs prefix matching from the beginning of the string.
  • Returns MatchResult with match status, positions, and capture groups.
  • Equivalent to Python's re.match() - only matches at string start.
  • Uses greedy matching strategy for longest possible match.

find_all(const std::string_view &text)

  • Searches for all non-overlapping matches throughout the entire string.
  • Returns vector of MatchResult objects for each match found.
  • Equivalent to Python's re.findall() - scans left to right.
  • Handles zero-length matches by advancing position to prevent infinite loops.

escape(const std::string_view &text)

  • Escapes all regex metacharacters by prefixing them with backslashes.
  • Makes special characters (., *, +, ?, |, (), [], {}, ^, $, \, -) literal.
  • Equivalent to Python's re.escape() - useful for matching literal strings that may contain regex syntax.
  • Pre-allocates memory for efficiency.

Implementation Details

  • Built on NFA state machine with epsilon transition handling.
  • Supports capture groups via SAVE states.
  • Handles anchors (^, $), character classes, and dot wildcards.
  • Internal match_internal() function supports both anchored and unanchored matching.

#14

@san-rizz-777 san-rizz-777 force-pushed the reg_func branch 4 times, most recently from be02c82 to 32f2677 Compare February 7, 2026 10:38
@Ovetsarilish
Copy link
Member

Ovetsarilish commented Feb 8, 2026

I have merged @AbhishekRai456 's PR, please modify the include paths and files accordingly. I will check the logic of Match-er in the meantime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants