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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:02:53+00:00 2026-05-28T05:02:53+00:00

I trying to improve a textbox that filters a gridview, by implementing an enhanced

  • 0

I trying to improve a textbox that filters a gridview, by implementing an enhanced textbox that can identify AND, OR, NOT operators by searching for this keywords in the string the user inputs in the textbox.

I am trying to do a regular expression to group the results but I’m not very good at this and I am failing to get what I want.

An example of what I want is as follows:

string = "build1 and build2 and build3 or build4 or not build5 and not build6"

results in a split mode:

  • build1 and
  • build2 and
  • build3 or
  • build4 or not
  • build5 and not
  • build6

This is because then I will take the first for example and replace with

SomeTable.Name_Of_Build = 'build1' AND

SomeTable.Name_Of_Build = 'build2' AND …. so on

  • 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-05-28T05:02:54+00:00Added an answer on May 28, 2026 at 5:02 am

    I might recommend that instead of using a regular expression to group the results you do something like this. I think it would be more robust than trying to guess at the right regex.

    string filter = "build1 and buil2 and build3 or build4 or not build5"
    list<string> filterTokens = filter.Split(new char[] {' '})
    
    string gridViewFilter = "";    
    bool notEqual = false;
    
    foreach(string token in filterTokens)
    {
       if(token == "and")
       {
          gridViewFilter += "and"
       }
       else if(token == "or")
       {
         gridViewFilter += "or"
       }
       else if(token == "not")
       {
          notEqual = true;
       }
       else if(notEqual)
       {
          gridViewFilter += "SomeTable.Name_Of_Build <> '" + token + "'";
          notEqual = false;
       }
       else
       {
          gridViewFilter += "SomeTable.Name_Of_Build <> '" + token + "'";
       }
    }
    

    Also, if you really want to implement a robust and full featured sort you need to look into using Reverse Polish Notation (RPN). It would allow you to handle parentheses and order of operations. An RPN implementation would look something like this.

    private bool CheckForFilterMatch(string filter, List<string> values, bool exactMatch)
    {
        for (int i = 0; i < values.Count; i++)
        {
            values[i] = values[i].ToLower();
        }
    
        if (filter.Trim() == "")
        {
            return true;
        }
    
        List<string> rpn = GetPostFixNotation(filter);
    
        Stack<bool> output = new Stack<bool>();
    
        foreach (string token in rpn)
        {
            if (IsValue(token))
            {
                bool isMatch;
                if (exactMatch)
                {
                    isMatch = values.Contains(token.ToLower());
                }
                else
                {
                    isMatch = false;
                    foreach (string value in values)
                    {
                        isMatch = (value.IndexOf(token.ToLower()) != -1);
    
                        if (isMatch) break;
                    }
                }
    
                output.Push(isMatch);
            }
            else if (IsOperator(token))
            {
                bool operand1 = output.Pop();
                bool operand2 = output.Pop();
    
                if (token == "&")
                {
                    output.Push(operand1 && operand2);
                }
                if (token == "|")
                {
                    output.Push(operand1 || operand2);
                }
            }
        }
    
        return output.Pop();
    }
    
    
    public  List<string> GetPostFixNotation(string filter)
    {
        if (filter == "")
        {
            return new List<string>();
        }
    
        List<string> postFixNotation = new List<string>();
    
        Queue<string> output = new Queue<string>();
        Stack<string> operators = new Stack<string>();
    
        List<string> parsedFilter = ParseFilterTokens(filter);
    
        foreach (string token in parsedFilter)
        {
            if (IsValue(token))
            {
                output.Enqueue(token);
            }
            else if (IsOperatorNoParenth(token))
            {
                while (operators.Count > 0 && IsOperatorNoParenth(operators.Peek()))
                {
                    if ((operators.Count > 0 && (Precedence(token) <= Precedence(operators.Peek()))))
                    {
                        string operatorToReturn = operators.Pop();
                        output.Enqueue(operatorToReturn);
                    }
                    else break;
                }
    
                operators.Push(token);
            }
            else if (token == "(")
            {
                operators.Push(token);
            }
            else if (token == ")")
            {
                while (operators.Count > 0 && operators.Peek() != "(")
                {
                    output.Enqueue(operators.Pop());
                }
                operators.Pop();
            }
        }
    
        while (operators.Count > 0)
        {
            output.Enqueue(operators.Pop());
        }
    
        while (output.Count > 0)
        {
            postFixNotation.Add(output.Dequeue());
        }
    
        return postFixNotation;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to improve this interesting algorithm as much as I can. For now,
I'm trying to improve this plugin adding events handlers to toggle play/stop when you
I'm trying to improve my current algorithm for the 8 Queens problem, and this
I'm trying to improve my spring mvc configuration so as to not require a
Context: I'm trying to improve the values returned by the iPhone CLLocationManager, although this
I'm trying to improve my Javascript coding style and have been reading that it's
I am trying to improve my C++ by creating a program that will take
I am trying improve the fault tolerance in a JSP-page that is updated on
I am trying to improve my SQL query so that i could get only
I am always trying to improve my programming practices and this one habit of

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.