File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Pattern Matching Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pattern Matching Question" Watch "Pattern Matching Question" New topic
Author

Pattern Matching Question

Tariq Ahsan
Ranch Hand

Joined: Nov 03, 2003
Posts: 116
Hello,

The code below works for doing pattern matching. Wondering if there would be a better way where I do not have to create separate Pattern and Matcher objects the way I have it now.
Here's the code -


Thanks!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

Wondering if there would be a better way where I do not have to create separate Pattern and Matcher objects the way I have it now.


The string class has some convenience methods for regex. Under the covers, it still does create the pattern and matcher objects, but it will make your code shorter -- for example, the string class has a matches() method that will take a regex.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Tariq Ahsan
Ranch Hand

Joined: Nov 03, 2003
Posts: 116
Hi Henry,

Thanks for your suggestion. In the line of using Pattern do you think the following code change would be an alternative of what I wanted?


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pattern Matching Question
 
Similar Threads
How to check special characters in java code using Java.util.regex package
Please tell me whether this procedure is correct or not.
regex and backslash..
Matches() in Matcher Class
Regex - string matching