wood burning stoves 2.0*
The moose likes Java in General and the fly likes text parsing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "text parsing" Watch "text parsing" New topic

text parsing

Michael Cleary
Ranch Hand

Joined: Jul 29, 2003
Posts: 93
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 />mdcleary@earthlink.net<br />----------------------------<br />There are 10 types of people<br />in the world. Those that <br />understand binary, and those<br />that don't.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41152
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 - my free Android networking tools app
Michael Cleary
Ranch Hand

Joined: Jul 29, 2003
Posts: 93
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.

Henry Wong

Joined: Sep 28, 2004
Posts: 18545

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.


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

Joined: Jul 29, 2003
Posts: 93
I'll take a look - thanks! And yeah, I use regex in PERL on a daily basis! I was hoping Java had something similar - I've just never used it before.

Thanks again,
I agree. Here's the link: http://aspose.com/file-tools
subject: text parsing
Similar Threads
Tips to create this filter ...
How to parse html page
Java text parsing and html parsing
parsing files in applets
Populating ENTITY tag using batik