Hi,I'm making a program that seraches a html file for special lines, andI use theScanner class with a regex to find those lines. It is working well,but now I wan'tto extract data that is on lines directly following my searched line.If I could make bigregex that included several lines it would be no problem, but sincethe methodfindInLine() only searches one line at a time, I'm not sure how to doit.What is a good way to do this? I don't want a full blown html parser,just a way tofind some 3-4 lines with same structure that are repeated severaltimes in a document.As I said, if I could somehow could get a regex to span multiplelines, that would begood, I think. Another idea is to nest the searches, so that when Ifind the first lineI could call a method or something that manually gets the remainglines and extractthe data from them, but that sounds more complicated. I'm not sure.Any ideas?Thanks!
|
|
0
|
|
|
|
Reply
|
banansol (15)
|
4/1/2007 6:37:51 PM |
|
banansol@hushmail.com wrote:> Hi,> I'm making a program that seraches a html file for special lines, and> I use the> Scanner class with a regex to find those lines. It is working well,> but now I wan't> to extract data that is on lines directly following my searched line.> If I could make big> regex that included several lines it would be no problem, but since> the method> findInLine() only searches one line at a time, I'm not sure how to do> it.> What is a good way to do this? I don't want a full blown html parser,> just a way to> find some 3-4 lines with same structure that are repeated several> times in a document.> > As I said, if I could somehow could get a regex to span multiple> lines, that would be> good, I think. Another idea is to nest the searches, so that when I> find the first line> I could call a method or something that manually gets the remaing> lines and extract> the data from them, but that sounds more complicated. I'm not sure.> Any ideas?> > Thanks!> Can't you use Pattern.MULTILINE, or am I missing something?-- TechBookReport Java http://www.techbookreport.com/JavaIndex.html
|
|
0
|
|
|
|
Reply
|
TechBookReport
|
4/2/2007 10:44:45 AM
|
|
banansol wrote:> Hi,>> As I said, if I could somehow could get a regex to span multiple> lines, that would be> good, I think.I recently had good luck using a regex across several lines usingScanner.findWithinHorizon(Pattern pattern, int horizon).If horizon is 0, then the horizon is ignored and this method continuesto search through the input looking for the specified pattern without bound.> Another idea is to nest the searches, so that when I> find the first line> I could call a method or something that manually gets the remaing> lines and extract> the data from them, but that sounds more complicated. I'm not sure.> Any ideas?>while (scanner.hasNext()) { for (int i = 0; i < 4; i++) { String match = sc.findWithinHorizon(pattern, 0); if (match.endsWith(",")) {} if (match.startsWith("\"")) {} if (match.length() == 0){} if(i == 0){} else if(i == 1){} else if(i == 2){} else{} } list.add(match);}> Thanks!>
|
|
0
|
|
|
|
Reply
|
Jeff
|
4/2/2007 5:04:19 PM
|
|
|
2 Replies
390 Views
(page loaded in 0.064 seconds)
|