-4
String inputs ="td class=\"prodcatnamelinkwrap\"";
Pattern p = Pattern.compile("<td cellspacing=\"0\" align=\"center\" valign=\"bottom\" class=\"prodcatimagewrap\">");
Matcher m = p.matcher(inputs);

What should i want to do to match this format. Any one help me out Thanks in advance

How does the find method works. I have to match td height="45px" valign="top" from this text

td align="center" height="45px" valign="top">.

But it says false all the time

For reference please find my code


Pattern replace5 = Pattern.compile(".*\r?\n",Pattern.MULTILINE);

Matcher matcher5 = replace5.matcher("td[@height=\"45px\"][@valign=\"top\"]".replaceAll("[\\[\\@]+"," "));
                                                    pattern3 = Pattern.compile(matcher5.replaceAll(" ").replaceAll("\\//", "").replaceAll("\\]",""));

pm3 = pattern3.matcher("<td align="center" height="45px" valign="top">");

if(pm3.find())

....It always results in false.Can anyone help me out
  • Have you swapped the pattern with the input? It makes no sense to say you want to match this format when your input is just a subset of the required pattern. Do you want to change the input to match the pattern or change the pattern to match the input. Instead of just showing the code, add some info of what you want to accomplish. – Roger Lindsjö Jan 12 '12 at 12:11
  • 1
    Obligatory: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – Jonathan Jan 12 '12 at 12:24
  • As simple as it is i want to check the web page content .Whether this match with this tag td class=\"prodcatnamelinkwrap\" – christopher Athisayamani Jan 26 '12 at 18:03

1 Answers1

1

Don't reinvent the wheel. Use html parser like jsoup.

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • As simple as it is i want to check the web page content .Whether this match with this tag td class=\"prodcatnamelinkwrap\" – christopher Athisayamani Jan 29 '12 at 20:44
  • I got the fix.Below is the solution: String s= "This is a test \n \n some other strings some more strings"; Pattern p = Pattern.compile("td align=\"center\" height=\"45px\" valign=\"top\"",Pattern.MULTILINE); Matcher m = p.matcher(s); System.out.println(m.find()); – christopher Athisayamani Feb 01 '12 at 09:04