• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using regex in criteriaFind

 
Venita Glasfurd
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic