This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using regex in criteriaFind" Watch "Using regex in criteriaFind" New topic

Using regex in criteriaFind

Venita Glasfurd

Joined: Sep 11, 2002
Posts: 12
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='*'"}
[ 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:
subject: Using regex in criteriaFind
Similar Threads
Regular expression syntax
Regex where some parts match on multiple lines, but other parts doesn't?
Java regex?
please review criteriaFind -> good riddance from hateful "ANY"
Parsing text