It's not a secret anymore!
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

Please Help -Problem in Regular Expressions

Rashmi Raju

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 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.util.*;
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) {
URL yahoo = new URL("");
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() )

} 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

Joined: Oct 13, 2005
Posts: 46344
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:
subject: Please Help -Problem in Regular Expressions
jQuery in Action, 3rd edition