Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8630929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:08:42+00:00 2026-06-12T09:08:42+00:00

I am new to regular expressions. Recently I was presented with a task to

  • 0

I am new to regular expressions. Recently I was presented with a task to convert a wildcard pattern to regular expression. This will be used to check if a file path matches the regex.

For example if my pattern is *.jpg;*.png;*.bmp

I was able to generate the regex by spliting on semicolons, escaping the string and replaceing the escaped * with .*

String regex = "((?i)" + Regex.Escape(extension).Replace("\\*", ".*") + "$)";

So my resulting regex will be for jpg ((?i).*\.jpg)$)
Thien I combine all my extensions using the OR operator.

Thus my final expression for this example will be:

((?i).*\.jpg)$)|((?i).*\.png)$)|((?i).*\.bmp)$)

I have tested it and it worked yet I am not sure if I should add or remove any expression to cover other cases or is there a better format the whole thing

Also bear in mind that I can encounter a wildcard like *myfile.jpg where it should match all files whose names end with myfile.jpg

I can encounter patterns like *myfile.jpg;*.png;*.bmp

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:08:43+00:00Added an answer on June 12, 2026 at 9:08 am

    There’s a lot of grouping going on there which isn’t really needed… well unless there’s something you haven’t mentioned this regex would do the same for less:

     /.*\.(jpg|png|bmp)$/i
    

    That’s in regex notation, in C# that would be:

    String regex=new RegEx(@".*\.(jpg|png|bmp)$",RegexOptions.IgnoreCase);
    

    If you have to programatically translate between the two, you’ve started on the right track – split by semicolon, group your extensions into the set (without the preceding dot). If your wildcard patterns can be more complicated (extensions with wildcards, multi-wildcard starting matches) it might need a bit more work 😉

    Edit: (For your update)

    If the wild cards can be more complicated, then you’re almost there. There’s an optimization in my above code that pulls the dot out (for extension) which has to be put back in so you’d end up with:

     /.*(myfile\.jpg|\.png|\.bmp)$/i
    

    Basically ‘*’ -> ‘.*’, ‘.’ -> ‘\.'(gets escaped), rest goes into the set. Basically it says match anything ending (the dollar sign anchors to the end) in myfile.jpg, .png or .bmp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to regular expressions and i'm feeling this very difficult to solve: I
im new to regular expressions and would like to decipher this. return preg_replace(/[<>]/, '_',
I'm relativly new to regular expressions but I managed to create a working expression
I'm not sure how do this, as I'm pretty new to regular expressions, and
I'm new to regular expressions and tried to use the following concept: (?(id/name)yes-pattern|no-pattern) in
I'm new to regular expressions and I need to find a regular expression that
I'm new to regular expressions so forgive me if this is really basic. I
I'm new to Regular Expressions... I've been asked a regular expression that accepts Alphanumerics,
I am pretty new to regular expressions. I want to write a regular expression
I'm new to regular expressions so this isn't strictly a Notepad++ question. Here's the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.