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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:48:34+00:00 2026-06-14T20:48:34+00:00

I have to remove a word/words in my string for some cases. For example,

  • 0

I have to remove a word/words in my string for some cases. For example,
My string is incabcincdefinc inc. inc. For this I need to remove both inc. and inc.
ie, output should be incabcincdefinc.
ie, remove all incs as per the following conditions:

<space>inc<space>
<space>inc<.>
<space>inc<end string>
<space>inc
  • 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-14T20:48:35+00:00Added an answer on June 14, 2026 at 8:48 pm

    You can probably get away with something like this:

    str = str.replaceAll("[ ](?:inc|ltd|corp)\\b\\.?", "");
    

    The square brackets are only used to make the space characters in between more visible, they could be omitted, as long as the space is kept. Your conditions are met by asserting that there is a word boundary (\\b) after the business entity extension. That means that there is no letter, digit or underscore coming next (which captures all your conditions). Then the pattern also tries to include a literal period (\\.), but does not care if there is non (?). Everything is replaced with an empty string. Note that in your first condition I do not match and remove the space, because that would make SomeCompany inc inc become SomeCompanyinc.

    If you want to look for the extension case-insensitively, you need to use the longer syntax:

    Pattern pattern = Pattern.compile(
        "[ ](?:inc|ltd|corp)\\b\\.?",
        Pattern.CASE_INSENSITIVE
    );
    Matcher matcher = pattern.matcher(str);
    str = matcher.replaceAll("");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code, from this i want to remove some words
I have a list of words in which some are composed words, in example
I have a string, for example FastFood, how do I remove Food and leave
Possible Duplicate: Remove a word from a string I have a simple string var
I have remove some item from the list of the BxSlider carousel. But when
say I have a string like so Testing How could I have it remove
I have a string full of a few hundred words. How would I get
i have a list of words: string[] BAD_WORDS = { xxx, o2o } //
How to remove the anchor tag from a string, I have a large text
I have a DB with some text fields pasted from MS Word, and I'm

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.