Activity 11.2 Solution

There are two changes to the original program that are required. First, the table header needs to be changed so that it contains an extra column, highlighted below. We have also adjusted the column widths to accommodate the extra column:

            String HTMLtable =  "<TABLE width=\"80%\" border=\"1\">\n" +
                                "<TR>" +    
                                "<TD width=\"65%\"><B>URL</B></TD>" +
                                "<TD width=\"20%\"><B>Pattern</B></TD>" +
                                "<TD width=\"15%\"><B>Matched</B></TD>" +       
                                "</TR>\n";
        

Next, the code that extracts the substring needs to be written and the HTML for the new row needs to be created by modifying the old HTML. The main changes to SearchDetails.java are highlighted below. The column widths can also be changed as suggested below to make a tidier layout:

            if(searchPattern.match(searchString))
            {
                //Search string has been found
                //Issue a line of the table 
            
                String matched = searchPattern.getParen(0);
            
                HTMLtable += (  "<TR>" +
                                "<TD width=\"65%\">" + uRLValue + "</TD>\n" +
                                "<TD width=\"20%\">" + regExps + "</TD>\n" +
                                "<TD width=\"15%\">" + matched + "</TD>\n" + 
                                "</TR>\n"
                              );
                found = true;
            }