Can anyone point me to any references/examples of parsing text in java? I basically need to search lines in a text file and look for certain patterns, etc. Are there some regular expression classes / methods that are useful for this sort of thing?
Mike<br />SCJP 1.4<br />----------------------------<br />email@example.com<br />----------------------------<br />There are 10 types of people<br />in the world. Those that <br />understand binary, and those<br />that don't.
Well, what kind of patterns are you looking for? If they're just words or phrases, then String.indexOf might be all you need. If it's more complicated, then the String.matches and String.split methods (and of course the whole java.util.regex package) provide regular expression support.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Jul 29, 2003
The patterns will vary a bit. One will be a persons name in the form of either "lastname" or "lastname MI". Another might be a number in the form of "3.00" (no quotes on any of them of course). I'm trying to help my son out a bit w/ an assignment (and no, I'm not doing it for him). I got my SCJP a couple of years ago, got to work on one Java project at work, and since then I've been stuck in PERL. So unfortunately, I'm a little rusty w/ Java.
Java's regex package is almost as good as the PERL regex library. It is missing some features. And the regex as Java strings causes some extra backspaces -- but should be easy to pickup, if you are a PERL user of regex.