Can someone help me with this regular expression?

Discussion in 'Java' started by james.wooten1, Mar 10, 2009.

  1. Hello,

    I would like to be able to create a regular expression that will only
    return the lower ascii characters (ie: 0-127), and replace all other
    characters with a carriage return. Can anyone tell me the regex for

    james.wooten1, Mar 10, 2009
    1. Advertisements

  2. james.wooten1

    Albert Guest

    a écrit :
    Why doing it with a regexp ? Do it with the (casted) int value of the
    Albert, Mar 10, 2009
    1. Advertisements

  3. james.wooten1

    Mark Space Guest

    \p{ASCII} will match ASCII only characters. So will [\x00-\x7F]

    \P{ASCII} (note upper case P) will match everything except ASCII, so
    that might be what you use to match for a replace

    All this information can be found here, btw:


    String asciiOnly ( String s ) {
    return s.replaceAll( "\\P{ASCII}", "\r" );

    might do what you want (untested).
    Mark Space, Mar 10, 2009
  4. public class test {
    public static void main(String[] args) {
    String str = "Now is the time\u00fffor all good men";


    That will be $1.00 please :).
    Knute Johnson, Mar 10, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.