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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:55:57+00:00 2026-06-10T19:55:57+00:00

Basically I have a bunch of large strings that I want to remove spaces/punctuation/numbers

  • 0

Basically I have a bunch of large strings that I want to remove spaces/punctuation/numbers from, I just want the words.

This is my code:

String str = "hughes/conserdyne corp, unit <hughes capital corp> made bear stearns <bsc> exclusive investment banker develop market 2,188,933 financing design installation micro-utility systems municipalities. company systems self-contained electrical generating facilities alternate power sources, photovoltaic cells, replace public utility power sources.";
        String[] arr = str.split("[\\p{P}\\s\\t\\n\\r<>\\d]");
        for (int i = 0; i < arr.length; i++) {
                    if(arr[i] != null)
                 System.out.println(arr[i]);
        }

This is the output I get:

hughes
conserdyne
corp

unit

lt
hughes
capital
corp

made
bear
stearns

lt
bsc

exclusive
investment
banker
develop
market










financing
design
installation
micro
utility
systems
municipalities

company
systems
self
contained
electrical
generating
facilities
alternate
power
sources

photovoltaic
cells

replace
public
utility
power
sources

So as you can see, there’s a lot of white space and such appearing where commas and numbers used to be. I get this with or without that if condition on printing.

Yet, if I concatenate all of arr’s contents into a new string, and then split that with regex “\s+” it works and produces the correct output.

So what’s wrong with my current regex? Any help would be appreciated.

  • 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-10T19:55:59+00:00Added an answer on June 10, 2026 at 7:55 pm

    You should just be able to throw a + on the end of your regex:

     String[] arr = str.split("[\\p{P}\\s\\t\\n\\r<>\\d]");
    

    To:

     String[] arr = str.split("[\\p{P}\\s\\t\\n\\r<>\\d]+");
                                                     // ^-- This guy
    

    Adding the + means to match 1 or more of the previous element, so if you have multiple “break characters” in a row, they will be treated as a single delimiter and you won’t get empty Strings in your result.

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

Sidebar

Related Questions

I basically have this url that has a bunch of information that I want
Basically I have a table with a bunch of numbers coming from a database
So basically, I have a bunch of TextBoxes that the user gets to fill
I have a page that will basically be used to concatenate a bunch of
have one time consuming step that flattens a bunch of files. basically i'd like
I basically have a program that filters records from one excel file to another
Basically I have a bunch of submission forms that gather data in a generic
Hopefully this is an easy one for someone. Basically I have a bunch of
I'm getting confused by pointers in objective-c. Basically I have a bunch of static
I basically have three tables, posts, images and postimages (this simply contains the ids

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.