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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:44:05+00:00 2026-05-23T10:44:05+00:00

I am processing user input on a search page. If the user selects an

  • 0

I am processing user input on a search page. If the user selects an ‘All Words’ type search, then I remove any boolean search operators from the search text and stick ' AND ' between each real word. Pretty simple in most cases. However, I can’t figure out how to remove two boolean operators in a row.

Here is my code:

// create the regex
private static Regex _cleaner =
     new Regex("(\\s+(and|or|not|near)\\s+)|\"", 
          RegexOptions.Compiled | RegexOptions.IgnoreCase);

// call the regex
_cleaner.Replace(searchText, " ")

The problem occurs when a user enters a search string like coffee and not tea. The regex will remove the ‘and’, but not the ‘not’. The resulting string is ‘coffeenot tea’ – what I want is ‘coffee tea’.

The white space is required in the regex so I don’t remove ‘and’, ‘or’, etc when embedded in real words (like ‘band’ or ‘corps’).

I have temporarily resolved this by calling the clean method twice, which will remove two operators in a row (which is probably all I would ever need). But it is not very elegant, is it? I would really like to do it right. I feel like I am missing something simple…

  • 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-23T10:44:05+00:00Added an answer on May 23, 2026 at 10:44 am

    Try adding word boundaries:

    "\\b(and|or|not|near)\\b|\""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am processing a user input from the public with a javascript WYSIWYG editor
If a page is called that requires a lot of processing and the user
After processing form from POST I should redirect, to prevent user from hitting back.
I need to do some Natural Language Processing on various text inputs from user
I need to do some processing after my user leaves a text field. I
I'm creating a non-intrusive popup window to notify the user when processing a time-consuming
I'm developing an application that needs to perform some processing on the user's Outlook
I need to do some processing only after the user has successfully logged in
So the chain of events is: The user submits a form. During the processing
My view calls some backend classes which need some user input. When user input

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.