• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

text parsing

 
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,
 
Rancher
Posts: 43009
76
  • 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,
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Boost this thread!