File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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: 38765
    
  23
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help -Problem in Regular Expressions