Add Regex.Escape via cre2_quote_meta#36
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/crispthinking/IronRe2/sessions/8e5472b7-ecbc-4fe7-8565-9cac67d0b3ae Co-authored-by: corpo-iwillspeak <265613520+corpo-iwillspeak@users.noreply.github.com>
corpo-iwillspeak
approved these changes
Apr 28, 2026
Copilot
AI
changed the title
[WIP] Add method similar to Regex.Escape for IronRe2
Add Regex.Escape via cre2_quote_meta
Apr 28, 2026
There was a problem hiding this comment.
Pull request overview
Adds an Escape API to IronRe2’s Regex class (backed by RE2’s “quote meta” functionality via cre2_quote_meta) so callers can safely turn literal text/bytes into a regex pattern that matches literally.
Changes:
- Added
cre2_quote_metaP/Invoke declaration inRe2Ffi. - Added
Regex.Escape(string)andRegex.Escape(ReadOnlySpan<byte>)implementations. - Added xUnit tests covering basic escaping and a literal-match smoke test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/IronRe2/Re2Ffi.cs |
Adds native interop signature for cre2_quote_meta. |
src/IronRe2/Regex.cs |
Adds public Escape APIs and unmanaged interop/cleanup logic. |
test/IronRe2.Tests/RegexTests.cs |
Adds test coverage for the new Regex.Escape APIs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@copilot apply changes based on the comments in this thread |
…est cases Agent-Logs-Url: https://github.com/crispthinking/IronRe2/sessions/c34a446d-62c5-4937-a8a6-e3ad138c90c7 Co-authored-by: corpo-iwillspeak <265613520+corpo-iwillspeak@users.noreply.github.com>
Contributor
Author
Done in bde98bf:
|
corpo-iwillspeak
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IronRe2 lacked a way to escape regex metacharacters for literal matching — useful when building patterns programmatically or integrating with RE2-based systems (e.g. Prometheus).
Changes
Re2Ffi.cs— P/Invoke binding forcre2_quote_meta, which delegates toRE2::QuoteMetaRegex.cs— Two staticRegex.Escapeoverloads:stringandReadOnlySpan<byte>. The native function heap-allocates the result viamalloc; freed withNativeMemory.Freefor cross-platform correctnessRegexTests.cs— Tests for metacharacter escaping, plain strings, empty input, and a round-trip literal matchUsage