Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    11
    Rep Power
    0

    Default Replacing all non-alphanumeric characters with empty strings

    is there a way to completely replace any non-alphanumeric char with an empty string

    i found something like this:
    Java Code:
    return value.replaceAll("\\W", "");
    Java Code:
    return value.replaceAll("[\\W]|_", "");
    but i dont really understand what they both do, so can you explain them to me and what the difference is please

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Replacing all non-alphanumeric characters with empty strings

    Have you read the documentation of java.util.regex.Pattern?

    Here's another learning resource: Regular-Expressions.info - Regex Tutorial, Examples and Reference - Regexp Patterns

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2012, 12:31 AM
  2. Replacing number characters with blanks
    By rpark712 in forum New To Java
    Replies: 3
    Last Post: 01-26-2012, 03:15 PM
  3. Replacing characters at a certain index
    By Slayer in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 09:49 PM
  4. Searching and replacing characters in a File
    By DBaskov in forum New To Java
    Replies: 3
    Last Post: 01-31-2011, 11:39 PM
  5. replacing characters???
    By manda147 in forum New To Java
    Replies: 2
    Last Post: 11-29-2008, 08:19 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •