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 Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    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, 01:31 AM
  2. Replacing number characters with blanks
    By rpark712 in forum New To Java
    Replies: 3
    Last Post: 01-26-2012, 04:15 PM
  3. Replacing characters at a certain index
    By Slayer in forum New To Java
    Replies: 2
    Last Post: 03-10-2011, 10:49 PM
  4. Searching and replacing characters in a File
    By DBaskov in forum New To Java
    Replies: 3
    Last Post: 02-01-2011, 12:39 AM
  5. replacing characters???
    By manda147 in forum New To Java
    Replies: 2
    Last Post: 11-29-2008, 09: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
  •