File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Regex pattern to be used Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Regex pattern to be used" Watch "Regex pattern to be used" New topic
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
    
    2
In the Matcher API, take a look at the difference between matches() and find().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex pattern to be used
 
Similar Threads
Regex
String replaceAll problem
java regx search or string char search
Combine two Regular expressions
regex doubt