Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Trouble with regex.. need help

Thread Tools

Trouble with regex.. need help

o2a1 o2a1 is offline
Junior Member
Join Date: Feb 2011
Posts: 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

and heres the code i got so far

import java.util.Scanner;

public class Word
public static void main(String[] args)
Scanner input = new Scanner(;
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]
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
i have no trouble to send , ihave trouble reciving mail --any ideas John Penney Computer Support 4 08-29-2006 08:45 PM
Trouble connecting to modem. Need some help. Bill Cisco 8 08-07-2006 11:25 AM
photoshop trouble, need help vikinartist Digital Photography 8 02-13-2005 09:18 AM
new pc crashes all the time, need trouble shooting help. Diehard Computer Information 14 01-14-2004 05:57 AM
trouble with caching or caching the trouble Hypo ASP .Net 6 08-01-2003 07:11 AM