newbie: match non numeric non whitespace value

Discussion in 'Java' started by usgog@yahoo.com, Feb 7, 2007.

  1. Guest

    I want to detect whether the java String has any non-numeric and non-
    whitespace char. For example,
    "12 34" returns false
    "1234" returns false
    "12a3" returns true
    " a 12 3" returns true

    Can I use [^0-9\\s]? If not, what does it mean?
    , Feb 7, 2007
    #1
    1. Advertising

  2. John Guest

    wrote:
    > I want to detect whether the java String has any non-numeric and non-
    > whitespace char. For example,
    > "12 34" returns false
    > "1234" returns false
    > "12a3" returns true
    > " a 12 3" returns true
    >
    > Can I use [^0-9\\s]? If not, what does it mean?
    >


    Here, try looking for something in the methods of the String class

    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

    I'm thinking you should be able to use the "matches" method to do what
    you want if you can figure out the regular expression business.
    John, Feb 8, 2007
    #2
    1. Advertising

  3. Guest

    On Feb 7, 7:30 pm, John <> wrote:
    > wrote:
    > > I want to detect whether the java String has any non-numeric and non-
    > > whitespace char. For example,
    > > "12 34" returns false
    > > "1234" returns false
    > > "12a3" returns true
    > > " a 12 3" returns true

    >
    > > Can I use [^0-9\\s]? If not, what does it mean?

    >
    > Here, try looking for something in the methods of the String class
    >
    > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
    >
    > I'm thinking you should be able to use the "matches" method to do what
    > you want if you can figure out the regular expression business.


    Thanks for the reply. The regular expression business is the thing
    that I am asking for help. :)
    , Feb 8, 2007
    #3
  4. Guest

    On Feb 8, 2:31 pm, "" <> wrote:
    > On Feb 7, 7:30 pm, John <> wrote:
    >
    >
    >
    >
    >
    > > wrote:
    > > > I want to detect whether the java String has any non-numeric and non-
    > > > whitespace char. For example,
    > > > "12 34" returns false
    > > > "1234" returns false
    > > > "12a3" returns true
    > > > " a 12 3" returns true

    >
    > > > Can I use [^0-9\\s]? If not, what does it mean?

    >
    > > Here, try looking for something in the methods of the String class

    >
    > >http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

    >
    > > I'm thinking you should be able to use the "matches" method to do what
    > > you want if you can figure out the regular expression business.

    >
    > Thanks for the reply. The regular expression business is the thing
    > that I am asking for help. :)- Hide quoted text -
    >
    > - Show quoted text -


    So basically you want to know if there are any alpha characters in the
    string. So, why not just use ([a-zA-Z]) in the regex expression?
    , Feb 8, 2007
    #4
  5. Guest

    On Feb 8, 1:35 pm, ""
    <> wrote:
    > On Feb 8, 2:31 pm, "" <> wrote:
    >
    >
    >
    > > On Feb 7, 7:30 pm, John <> wrote:

    >
    > > > wrote:
    > > > > I want to detect whether the java String has any non-numeric and non-
    > > > > whitespace char. For example,
    > > > > "12 34" returns false
    > > > > "1234" returns false
    > > > > "12a3" returns true
    > > > > " a 12 3" returns true

    >
    > > > > Can I use [^0-9\\s]? If not, what does it mean?

    >
    > > > Here, try looking for something in the methods of the String class

    >
    > > >http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

    >
    > > > I'm thinking you should be able to use the "matches" method to do what
    > > > you want if you can figure out the regular expression business.

    >
    > > Thanks for the reply. The regular expression business is the thing
    > > that I am asking for help. :)- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > So basically you want to know if there are any alpha characters in the
    > string. So, why not just use ([a-zA-Z]) in the regex expression?


    I think [a-zA-Z] won't cover i18n characters.
    , Feb 8, 2007
    #5
  6. Lew Guest

    wrote:
    >>>>> I want to detect whether the java String has any non-numeric and non-
    >>>>> whitespace char. For example,
    >>>>> "12 34" returns false
    >>>>> "1234" returns false
    >>>>> "12a3" returns true
    >>>>> " a 12 3" returns true
    >>>>> Can I use [^0-9\\s]? If not, what does it mean?


    > I think [a-zA-Z] won't cover i18n characters.


    Try "\\p{L}". Read
    <http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html>

    Study it.

    - Lew
    Lew, Feb 9, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oli Filth
    Replies:
    9
    Views:
    3,314
    Uncle Pirate
    Jan 17, 2005
  2. Replies:
    5
    Views:
    909
    X-Centric
    Jun 30, 2005
  3. darrel
    Replies:
    4
    Views:
    786
    darrel
    Jul 19, 2007
  4. Replies:
    10
    Views:
    717
    Eric Brunel
    Dec 16, 2008
  5. MRAB
    Replies:
    3
    Views:
    368
Loading...

Share This Page