Regular expression help

Discussion in 'Java' started by Manish Hatwalne, Dec 16, 2003.

  1. I am trying few things with regular expression, I would like to allow
    following characters, how do I do this?
    N
    N-N
    N+
    N-
    N,N

    wher N is a digit.

    TIA,
    - Manish
     
    Manish Hatwalne, Dec 16, 2003
    #1
    1. Advertisements

  2. Manish Hatwalne

    Virgil Green Guest

    The first thing I'd do if learning regex is download the free (for
    non-commercial use) Regex Coach at http://www.weitz.de/regex-coach/

    I'm unsure of your question, though. Do you want to allow any of those
    patterns in a string?

    - Virgil
     
    Virgil Green, Dec 16, 2003
    #2
    1. Advertisements

  3. Thanks a ton for regex-coach link!!!

    I sort of figured it out (with some help from friends), and got thisone
    which works for single comma, I am just looking for a small modification
    that will work for multiple commas.

    This is what I have, which works for single comma
    [0-9]+[-+,]?[0-9]*

    My valid strings would be -

    1234
    1234+
    1234-
    1234-5678
    123,456,789
    123,456

    I'd prefer if I could get the pattern that I have got a bit modified so as
    to work for my multiple comms requiement.

    TIA,
    - Manish
     
    Manish Hatwalne, Dec 16, 2003
    #3
  4. Manish Hatwalne

    Chris Smith Guest

    Looks to me like:

    [0-9]([\-\+\,]([0-9])?)?

    That's assuming you also want to allow "N+N" and "N,". If not, please
    be more clear about what you want. (Or is it *just* the list above? in
    which case "[0-9]((\,[0-9])|\+|(\-[0-9]?))?" looks like it might work.)

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Dec 16, 2003
    #4
  5. Manish Hatwalne

    Alan Moore Guest

    \d+(\+|-\d*|(,\d+)+)?
     
    Alan Moore, Dec 17, 2003
    #5
    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.