I need a regular expression...

Posted on 2006-04-11
Last Modified: 2010-03-31
I need a regular expression (I'm not familiar with them), to be used with String.replaceall. It needs to match and replace the following characters comma, double quote, carriage return, and linefeed. If you could also explain how it works so that I can start learning how to do this that would be great.

Worth 500 points.

Question by:richardsimnett
    LVL 86

    Accepted Solution

    s = s.replaceAll("[,\"\r\n]", "");

    There's not much to explain other than it taking any of the chars in the character class and replacing them with an empty String
    LVL 14

    Assisted Solution

    replaceAll("[,\"\n\r]", "what ever string to be instead of those chars");

    All info about regex is in class java.util.regex.Pattern overview
    LVL 84

    Expert Comment

    LVL 92

    Expert Comment

    [] defines characters classes, in this case to match any character character listed
    carriage return is specified by \r
    new line is specified using \n
    " needs to be escaped in a java string \" so it isn't treated as closing the string
    LVL 86

    Expert Comment


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now