• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

text parsing

 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks,
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,
 
Henry Wong
author
Marshal
Pie
Posts: 21021
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
Michael Cleary
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic