Hi,
I have a mostly functioning program (for uni) but I can not seem to get one module to work.
- I want to read in a String from the keyboard. (I know how to do this).
- I need to then make sure the string is only a word, so I want to do a regex check to see if it contains any punctuation or anything but [a-z]. And return a boolean expression (this I dont know how to do, well o can't get it to work).
- I want to then to have a DOWHILE loop to repeat until the entry is valid (only a-z characters)
I have read online about using the regex [^\w] or \p{Punct} but I don't know how to make it work..
I am new to java so be nice please and also make the steps very clear, I am new to classes as well.
Ok Thanks..
ND
Comparing or matching strings.
Started by ns_uni, May 18 2009 01:34 AM
4 replies to this topic
#1
Posted 18 May 2009 - 01:34 AM
|
|
|
#2
Posted 18 May 2009 - 01:35 AM
Whoops the title should have been called comparing a string to a regex..
HELP!
HELP!
#3
Posted 18 May 2009 - 02:51 AM
I think you want "^[\w]*$"
#4
Posted 18 May 2009 - 05:24 AM
Ok scrap that...
I need to check a string to see if it contains any punctuation characters.. if it does i need to return a boolean ...
The best way to do this is?
Anyone??
I need to check a string to see if it contains any punctuation characters.. if it does i need to return a boolean ...
The best way to do this is?
Anyone??
#5
Posted 18 May 2009 - 09:21 AM
Go here:
gskinner
.
com
/
RegExr
/
I have to break up the link because I don't post enough to write a true link in my comments, apparently.
anyway, there are two things here, are you looking for non-letters and numbers? "[^1-9a-zA-Z ]"? or are you looking for sentence enders "[?.!]*"? oh, and are you looking to return the very first one you fine (if any) or all of them?
gskinner
.
com
/
RegExr
/
I have to break up the link because I don't post enough to write a true link in my comments, apparently.
anyway, there are two things here, are you looking for non-letters and numbers? "[^1-9a-zA-Z ]"? or are you looking for sentence enders "[?.!]*"? oh, and are you looking to return the very first one you fine (if any) or all of them?


Sign In
Create Account


Back to top









