0

Here is a part of my document:

<td align="right" valign="top"><b>Име:</b></td> <td align="left" valign="top">Павлин Евгениев Тишев</td>
<td rowspan="7" align="center" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td align="right" valign="top"><b>Състояние:</b></td>
<td align="left" valign="top">Редовен</td>

I want to extract the String between <td align="left" valign="top"> and </td> from all occurrences one by one because the values are ordered by type.

I am using this code (in is the whole input String part of which is shown above)

Pattern p = Pattern.compile("<td align=\"left\" valign=\"top\">(.*?)</td>");
        Matcher m = p.matcher(in);

        if (m.matches()) {
            student.setName(m.group(1));
            student.setState(m.group(2));
        }

but it does not even enter the if

VLAZ
  • 26,331
  • 9
  • 49
  • 67

1 Answers1

2

You should use this:

while (m.find()) {
            student.setName(m.group(1));
            student.setState(m.group(2));
        }

Read this for understanding exactly why should you use find() and not matches().

Community
  • 1
  • 1
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108