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 7917811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:16:41+00:00 2026-06-03T15:16:41+00:00

I wonder if it is possible to modify a wildcard expression that uses *

  • 0

I wonder if it is possible to modify a wildcard expression that uses * and ? to transform it into a regular expression to verify if it matches some strings.

In other word, if I use filter (case insensitive): *bl?e* on those strings:

["Blue", "Black", "Red", "Light blue", "Light black"]

I want to get:

["Blue, "Light blue"].

Does anybody know how to do that with regular expression?
Is there a better way to do that other than using regular expression?

Added to better clarify my thought…

Ok! … as always, I thought I ask a super clear question and realize by the answers that I totally screw up my question. I would like to do a function that would filter a collection according to an expression (as a parameter to my function) that as same rules as dos (‘*’ ‘?’). I thought that using regex would be a nice idea. Am I right and what is the regex expression ? Also… I’m using C# and I wonder if I don not have access to anything that would do the job directly ?

I also look at (pretty good answer) How do I specify a wildcard (for ANY character) in a c# regex statement?

I finally used Glob class in .net Patterns and Practices library.

But as reference this is my code to translate Glob exp to RegEx:

using System.Text;
using System.Text.RegularExpressions;

namespace HQ.Util.General
{
    public class RegexUtil
    {
        public const string RegExMetaChars = @"*?(){}[]+-^$.|\"; // Do not change the order. Algo depends on it (2 first chars should be dos like wildcard char)

        // ******************************************************************
        /// <summary>
        /// Convert an filter expression with '*' (wildcard any char) and '?' (wildcard on char) into a valid regex and
        /// strip any special regex character
        /// </summary>
        /// <param name="dosLikeExpressionFilter"></param>
        /// <returns></returns>
        public static string DosLikeExpressionFilterToRegExFilterExpression(string dosLikeExpressionFilter)
        {
            StringBuilder regex = new StringBuilder();
            regex.Append("(?i)"); // Case insensitive

            int startIndex = 0;
            int count = dosLikeExpressionFilter.Length;
            while (startIndex < count)
            {
                int metaIndex = RegExMetaChars.IndexOf(dosLikeExpressionFilter[startIndex]);
                if (metaIndex >= 0)
                {
                    if (metaIndex == 0)
                    {
                        regex.Append(".*");
                    }
                    else if (metaIndex == 1)
                    {
                        regex.Append(".");
                    }
                    else
                    {
                        regex.Append("\\");
                        regex.Append(dosLikeExpressionFilter[startIndex]);
                    }
                }
                else
                {
                    regex.Append(dosLikeExpressionFilter[startIndex]);
                }
                startIndex++;
            }

            return regex.ToString();
        }

        // ******************************************************************
        /// <summary>
        /// See 'DosLikeExpressionFilterToRegExFilterExpression' description to see what type of Regex is returned
        /// </summary>
        /// <param name="dosLikeExpressionFilter"></param>
        /// <returns></returns>
        public static Regex DosLikeExpressionFilterToRegEx(string dosLikeExpressionFilter)
        {
            return new Regex(DosLikeExpressionFilterToRegExFilterExpression(dosLikeExpressionFilter));
        }

        // ******************************************************************
    }
}
  • 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-03T15:16:43+00:00Added an answer on June 3, 2026 at 3:16 pm
                   Any single character    Any number of characters   Character range
    Glob syntax            ?                           *                    [0-9]
    Regex syntax           .                           .*                   [0-9]
    

    So Bl?e (glob) becomes Bl.e (regex), and *Bl?e* becomes .*Bl.e.*.

    As Joey correctly noted, you can (usually, depending on the regex engine) prepend (?i) to your regex to make it case-insensitive.

    Be aware, though, that lots of characters that have no special meaning in globbing patterns do have special meaning in regex, so you can’t just do a simple search-and-replace from glob to regex.

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

Sidebar

Related Questions

I wonder whether it is possible to use Django in-built comments framework for other
I wonder is it possible to write a console application that will surf to
I wonder if it possible to not have jython automagicaly transform java objects to
I wonder it is possible to use Boost.PHP to replace some PHP core functions
I just had an idea that I wonder whether is possible in java. Let's
I wonder is it possible to have a map that would work like boost
I wonder if it is possible to use FK's in Mysql (InnoDB) for inverse
I wonder if it's possible to create an extension method which has functionality &
I wonder if is it possible to run mysql command which can select an
I wonder if it's possible to programmaticaly share folders in Windows 7 while running

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.