aspose file tools*
The moose likes Beginning Java and the fly likes Please Help -Problem in Regular Expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please Help -Problem in Regular Expressions" Watch "Please Help -Problem in Regular Expressions" New topic
Author

Please Help -Problem in Regular Expressions

Rashmi Raju
Greenhorn

Joined: Apr 24, 2008
Posts: 4
Hi Everybody I am in need of your help in correcting my code . I am not an expert in Regular expressions I want to open a URL say shopping.com and display only the tables in that particular web page.....
My code below is not working to display all tables in the web page ...........
Can anybody help me to corret the code Since I need to submit my code at the earliest any help would be really appreciated.............
Thanks a lot in advance............
My code is below...........
import java.net.*;
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


class ConnectionTest {
public static void main(String[] args) {
try
{
URL yahoo = new URL("http://www.shopping.com");
URLConnection yahooConnection = yahoo.openConnection();
DataInputStream dis = new DataInputStream(yahooConnection.getInputStream());

String inputLine;

Pattern regexp = Pattern.compile("<table(.*?)</table>", Pattern.DOTALL);



while ((inputLine = dis.readLine()) != null) {
Matcher matcher = regexp.matcher(inputLine);


matcher.reset( inputLine ); //reset the input
if ( matcher.find() )
{


System.out.println(matcher.group());
}
}
dis.close();
} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
}

It just comes out of the loop without displaying anything anybody please help me out.................
Waiting for your guidance and help in regular expressions Please
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Welcome to the Ranch.

This is the Java Tutorial about regular expressions.

There is something not quite right about your regex; you are matching any character any number of times then maybe once or not at all. It is the .*? bit. All three of those characters are meta-characters; . means anything-not-line-end, * means any number including 0 and ? means 0 or 1.

Not sure exactly what you need, but I think you will find the tutorial helpful. Take some time over it; regular expressions are by no means easy.
[ April 24, 2008: Message edited by: Campbell Ritchie ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Please Help -Problem in Regular Expressions
 
Similar Threads
Finding the largest table ina web page and displaying it
Display tables from web page
Problem in extracting tables from a web page
can i get other website contents in my webapplication
about URL access (Please help me