| Author |
Regex pattern to be used
|
rakesh kadulkar
Ranch Hand
Joined: Jul 24, 2008
Posts: 115
|
|
Hi,
I am accepting a string from the user and I want some set of characters should not be there in the string.
For example in a string I accept from the user I dont want any character other than IVXLCDM to exist.
What regex I have to use.
|
Rakesh Kadulkar
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Why don't you look at the Javadoc of java.util.regex.Pattern and then tell us what you've come up with yourself.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
rakesh kadulkar
Ranch Hand
Joined: Jul 24, 2008
Posts: 115
|
|
I have tried [^IXCVDM].
i WANT that any character other than this to be detected but it does not work.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
That regex is good if you use it properly. How do you use it in your code?
|
 |
rakesh kadulkar
Ranch Hand
Joined: Jul 24, 2008
Posts: 115
|
|
Pattern p = Pattern.compile("[^IVXLCMD]");
Matcher m = p.matcher();
m.matches() if it returns true i want to reject the input.
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2782
|
|
|
In the Matcher API, take a look at the difference between matches() and find().
|
 |
 |
|
|
subject: Regex pattern to be used
|
|
|