Trouble with regex.. need help

Discussion in 'Java' started by o2a1, Feb 12, 2011.

  1. o2a1

    o2a1

    Joined:
    Feb 12, 2011
    Messages:
    1
    ok what am i doing wrong, my program has to output and evaluate a string,

    heres 3 examples of how it is supposed to run,

    eg.1 (no string entered)
    "java Word
    Usage: java Word <string>"


    eg.2(string containing punctuation and numbers gives the output "The string must consist of letters!")
    "java Word AAABB@I5P
    The string must consist of letters!"


    eg.3(continous character gives the output)
    "java Word AAAAAAAwwwwwwwwwwwTTT
    7A11w3T"


    and heres the code i got so far

    import java.util.Scanner;
    import java.io.PrintStream;

    public class Word
    {
    public static void main(String[] args)
    {
    Scanner input = new Scanner(System.in);
    PrintStream output = System.out;

    output.print("java Word ");
    String s = input.nextLine();
    if (s.equals(""))
    {
    output.print("Usage: java Word <string>");
    }
    if (s.matches("[^0-9]*[0-9]+[^0-9]*"))
    {
    output.print("The string must consist of letters!");
    }
    if (s.matches("[\\p]")) //is this the correct code for all punctuations??
    {
    output.print("The string must consist of letters!");
    }

    }
    }


    when i enter a number i get the correct output, however I am not sure on how to exclude punctuations from the string and i get a weird error when typing in [\\p]
     
    o2a1, Feb 12, 2011
    #1
    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. Hypo
    Replies:
    6
    Views:
    462
  2. Fernando Rodriguez

    Trouble with regex

    Fernando Rodriguez, Nov 14, 2003, in forum: Python
    Replies:
    2
    Views:
    293
    Jim Shapiro
    Nov 14, 2003
  3. Fernando Rodriguez
    Replies:
    5
    Views:
    429
    Roel Mathys
    Nov 20, 2003
  4. marek

    unicode regex example: trouble

    marek, May 21, 2004, in forum: Python
    Replies:
    1
    Views:
    377
    Peter Otten
    May 21, 2004
  5. seberino@spawar.navy.mil
    Replies:
    3
    Views:
    832
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page