File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using regex in criteriaFind Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using regex in criteriaFind" Watch "Using regex in criteriaFind" New topic
Author

Using regex in criteriaFind

Venita Glasfurd
Greenhorn

Joined: Sep 11, 2002
Posts: 12
Hi,
After reading many posts here, I've decided to go with jdk1.4 for my assignment and have this question regarding regex.
I've modified the toString method in DataInfo to return a String which can be parsed using regex. I have the following code as part of my criteriaFind.

Is there some way I can eliminate the for loop above and use an And condition instead?
Sample data for the criteriaArray is below.
{"Carrier='SpeedyAir'", "Origin airport='*'"}
Venita
[ November 03, 2002: Message edited by: Venita Glasfurd ]
Pete Lyons
Ranch Hand

Joined: Aug 18, 2002
Posts: 109
There is no way to use a single Regex to get the AND logic you need for matching, AFAIK. Remember that the instructions explicitly allow you to do case-sensitive matching, which implies String.equals(). Your approach seems backward in that you have a nicely structured hunk of data that you put into a String, which you then run regular expressions against. Ususally, when you must parse string inputs, you try to parse them into a nice data structure and do your manipulation on that; your code does the opposite. I would Keep It Simple and re-implement your matching code for three reasons: it's round-about and somewhat inefficient, it's harder for a novice programmer to understand than a simpler matching mechanism, and it is a minor violation of the convention for toString(), which Sun says is supposed to be suitable for debugging purposes (not necessarily identification purposes).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using regex in criteriaFind
 
Similar Threads
please review criteriaFind -> good riddance from hateful "ANY"
Regular expression syntax
Regex where some parts match on multiple lines, but other parts doesn't?
Parsing text
Java regex?