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

  • Home
  • SEARCH
  • 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 7734229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:11:53+00:00 2026-06-01T07:11:53+00:00

I want to remove certain words from a string. The words I want to

  • 0

I want to remove certain words from a string. The words I want to remove are: “a”, “an”, “and”, “the”, “of”, and “or”.

I used the following method:

 void doNoiseEliminator(Vector<String> input){

        noNoiseLines = new Vector<String>();
        String temp;   

        for(int i = 0; i < input.size(); i++) {

            String regex = "(\\sand\\s)|(\\sa\\s)|(\\sthe\\s)|(\\san\\s)|(\\sof\\s)|(\\sor\\s)";
            temp = input.get(i).replaceAll(regex, " ");
            noNoiseLines.add(temp);            
        }
    }

But this does not seem to work. My program takes a string line and circular shifts the line.

For the following input :

MY NAME IS JOHN
MY NAME IS AN A SAM
MY NAME IS OR RAW

Output is :

  1. a sam my name is
  2. is a sam my name
  3. is john my name
  4. is raw my name
  5. john my name is
  6. my name is a sam
  7. my name is john
  8. my name is raw
  9. name is a sam my
  10. name is john my
  11. name is raw my
  12. raw my name is
  13. sam my name is a

Why is this happening? How can I correct this? Please help me. Thanks…!!!

  • 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-01T07:11:55+00:00Added an answer on June 1, 2026 at 7:11 am

    To be truthful I didnt understand your question fully, but try the simple way first, without regex, your problem might be there. Then go optimizing it if needed.

    For example, try something like this.

    void doNoiseEliminator(Vector input){

        noNoiseLines = new Vector<String>();
        String temp;   
    
        for(int i = 0; i < input.size(); i++) {
    
    
            temp = input.get(i).replaceAll(" a ", " ").replaceAll(" an ", " ").replaceAll(" and ", " ").replaceAll(" the ", " ").replaceAll(" of ", " ").replaceAll(" or ", " ");
            noNoiseLines.add(temp);            
        }
    }
    

    Of course this shouldnt be the final solution, its just to check if it works. Working, you can go towards checking/fixing the regex or any other solution.

    Hope it helped to guide to the solution, cya.

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

Sidebar

Related Questions

I want to remove every occurance of a certain value from a list. I
I want to remove all special characters from a string. Allowed characters are A-Z
I want to remove a IBOutlet UIimage from certain table cells: I have a
I want to delete certain words from a paragraph, such as and, as, and
I want to make a new list from another list of words; when a
I want to remove digits from a float to have a fixed number of
I want to remove all files from Git at ~/bin/. I run git rm
I want to remove duplicate rows return from a SELECT Query in Postgres I
I'm using libxml2 to parse HTML. I want to remove certain formatting tags like
I want to loop through a vector and erase certain elements that correspond to

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.