Skip to content

Add static extension Regex.FromWildcardPattern(string)#47

Merged
Tyrrrz merged 4 commits intoprimefrom
copilot/add-static-extension-regex-fromwildcardpattern
Apr 17, 2026
Merged

Add static extension Regex.FromWildcardPattern(string)#47
Tyrrrz merged 4 commits intoprimefrom
copilot/add-static-extension-regex-fromwildcardpattern

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

Adds a static extension method on Regex to construct a Regex from a shell-style wildcard pattern, where ? matches any single character and * matches any sequence of characters. All other characters (including regex metacharacters) are treated as literals via Regex.Escape.

Changes

  • PowerKit/Extensions/RegexExtensions.cs — new extension(Regex) block exposing Regex.FromWildcardPattern(string pattern, RegexOptions options = RegexOptions.None)
  • PowerKit.Tests/RegexExtensionsTests.cs — tests covering *, ?, combined patterns, exact matching, RegexOptions passthrough, and regex special-char escaping

Usage

Regex.FromWildcardPattern("*.txt").IsMatch("report.txt");          // true
Regex.FromWildcardPattern("file?.log").IsMatch("file1.log");       // true
Regex.FromWildcardPattern("(src).*", RegexOptions.IgnoreCase)      // literal parens
    .IsMatch("(src).cs");                                          // true

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 17, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 17, 2026 12:46
Copilot AI review requested due to automatic review settings April 17, 2026 12:46

namespace PowerKit.Tests;

public class RegexExtensionsTests
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to consolidate tests a little bit, there are too many @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consolidated from 7 methods down to 2 in 757dd1e: FromWildcardPattern_Test (covering *, ?, exact match, and special-char escaping) and FromWildcardPattern_WithOptions_Test.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.38%. Comparing base (e1aaff9) to head (c7ae006).
⚠️ Report is 3 commits behind head on prime.

Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #47      +/-   ##
==========================================
+ Coverage   94.36%   94.38%   +0.02%     
==========================================
  Files          82       86       +4     
  Lines        1740     1800      +60     
  Branches      141      143       +2     
==========================================
+ Hits         1642     1699      +57     
- Misses         72       74       +2     
- Partials       26       27       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Regex static extension API for turning shell-style wildcard patterns (*, ?) into anchored regular expressions, with accompanying unit tests in PowerKit.Tests.

Changes:

  • Introduces Regex.FromWildcardPattern(string pattern, RegexOptions options = RegexOptions.None) to convert wildcard patterns into a Regex.
  • Adds xUnit/FluentAssertions coverage for *, ?, mixed patterns, exact matching, options passthrough, and escaping of regex metacharacters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
PowerKit/Extensions/RegexExtensions.cs Adds Regex.FromWildcardPattern(...) implementation by escaping literals and translating */? into regex equivalents.
PowerKit.Tests/RegexExtensionsTests.cs Adds tests verifying wildcard behavior, escaping, and options passthrough.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit/Extensions/RegexExtensions.cs Outdated
Copilot AI requested a review from Tyrrrz April 17, 2026 12:50
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 17, 2026

@copilot please fix formatting

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

@copilot please fix formatting

Fixed in c7ae006 — ran CSharpier on RegexExtensions.cs to correct the expression-body formatting.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants