0

How would I get the matching strings?

I would like to get the figure after "text-align:right" - but only if the string machtes to following string.

<td style="text-align:left;">whatever characters</td>
                              <td style="text-align:right;">whatever characters</td>

The text I am searching looks like this:

<td style="text-align:left;">all kinds of 12.:-aäüKFfk characters </td>
                              <td style="text-align:right;">100.00</td>
                              <td style="text-align:right;">200.00</td>
                             ...more text...
                              <td style="text-align:left;">all kinds of 12.:-aäüKFfk characters</td>
                              <td style="text-align:right;">300.00</td>
                              <td style="text-align:right;">400.00</td>

This should print out to the console window the figures 100.00 and 300.00 But it does not show anything.

Pattern pattern = Pattern.compile("<td style=\"text-align:left;\">.</td>" + "\\s+" + "<td style=\"text-align:left;\">(.*?)</td>");
Matcher matcher = pattern.matcher(alltext);
    while (matcher.find()) {
        System.out.println(matcher.group(1));}

If I try only

Pattern pattern = Pattern.compile("<td style=\"text-align:left;\">(.*?)</td>");
Matcher matcher = pattern.matcher(alltext);
    while (matcher.find()) {
        System.out.println(matcher.group(1));}

it prints out all the figures 100.00, 200.00, 300.00 and 400.00

So the problem has to be in the this part

Pattern.compile("<td style=\"text-align:left;\">.</td>" + "\\s+" + 

What could be the problem and how could it be solved?

Tobias Mai
  • 111
  • 2
  • 6
  • 1
    [Obligatory reference.](http://stackoverflow.com/a/1732454/5044950) – Sam Estep Jun 28 '15 at 00:16
  • [Other obligatory reference.](http://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/) –  Jun 28 '15 at 01:17

0 Answers0