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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:51:31+00:00 2026-05-25T18:51:31+00:00

I want to remove special characters like: – + ^ . : , from

  • 0

I want to remove special characters like:

- + ^ . : ,

from an String using Java.

  • 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-25T18:51:31+00:00Added an answer on May 25, 2026 at 6:51 pm

    That depends on what you define as special characters, but try replaceAll(...):

    String result = yourString.replaceAll("[-+.^:,]","");
    

    Note that the ^ character must not be the first one in the list, since you’d then either have to escape it or it would mean “any but these characters”.

    Another note: the - character needs to be the first or last one on the list, otherwise you’d have to escape it or it would define a range ( e.g. :-, would mean “all characters in the range : to ,).

    So, in order to keep consistency and not depend on character positioning, you might want to escape all those characters that have a special meaning in regular expressions (the following list is not complete, so be aware of other characters like (, {, $ etc.):

    String result = yourString.replaceAll("[\\-\\+\\.\\^:,]","");
    

    If you want to get rid of all punctuation and symbols, try this regex: \p{P}\p{S} (keep in mind that in Java strings you’d have to escape back slashes: "\\p{P}\\p{S}").

    A third way could be something like this, if you can exactly define what should be left in your string:

    String  result = yourString.replaceAll("[^\\w\\s]","");
    

    This means: replace everything that is not a word character (a-z in any case, 0-9 or _) or whitespace.

    Edit: please note that there are a couple of other patterns that might prove helpful. However, I can’t explain them all, so have a look at the reference section of regular-expressions.info.

    Here’s less restrictive alternative to the “define allowed characters” approach, as suggested by Ray:

    String  result = yourString.replaceAll("[^\\p{L}\\p{Z}]","");
    

    The regex matches everything that is not a letter in any language and not a separator (whitespace, linebreak etc.). Note that you can’t use [\P{L}\P{Z}] (upper case P means not having that property), since that would mean “everything that is not a letter or not whitespace”, which almost matches everything, since letters are not whitespace and vice versa.

    Additional information on Unicode

    Some unicode characters seem to cause problems due to different possible ways to encode them (as a single code point or a combination of code points). Please refer to regular-expressions.info for more information.

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

Sidebar

Related Questions

I want to remove all special characters except space from a string using JavaScript.
I want to remove all special characters from a string. Allowed characters are A-Z
I want to remove all special characters from a string. Allowed characters are A-Z
I want to remove all whitespace characters from a multi-line string using regex. What
I want to remove all special characters (,/{}etc.) from an input field being saved
I want remove "Language" querystring from my url. How can I do this? (using
I'm using subversion (TortoiseSVN) and I want to remove the .svn folders from my
I have a bunch of java files from which I want to remove the
I have an ArrayList<String> , and I want to remove repeated strings from it.
I want to remove a UIView from a superview and add it again at

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.