We help IT Professionals succeed at work.
Get Started

Regex - wild card search results help!

teknovation asked
Last Modified: 2016-02-05
Does anyone know how I can tweak this string pattern to accept decimals? Right now we are able to search and find things but once there's a decimal in the string, the search cannot find it. It looks to be using Regex.

string pattern = @"(-[A-Za-z]*\d+[A-Za-z]*(-[A-Za-z]*\d+[A-Za-z]*)*)";

private SearchResponseData GetproductSearchResult(string searchText, string category = "")
        //WILDCARD results if search term contains a Catalog Number
        string pattern = @"(-[A-Za-z]*\d+[A-Za-z]*(-[A-Za-z]*\d+[A-Za-z]*)*)";
            //Try strong Regex
            string replacement = Regex.Replace(searchText, pattern, "$0*");
            keywordSearchCriteria = new KeywordSearchCriteria { QueryText = replacement };
        catch (Exception ex)
            //If syntax error, try weaker Regex
            if (Regex.IsMatch(searchText, "-(\\d)*"))
                keywordSearchCriteria = new KeywordSearchCriteria { QueryText = searchText + "*" };
            //Use search term as-is
                keywordSearchCriteria = new KeywordSearchCriteria { QueryText = searchText };

Open in new window

Watch Question
IT Consultant
This problem has been solved!
Unlock 1 Answer and 23 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE