106.2% or ...">

C # regex - something or nothing

I have two types of possible strings for getting information:

<td class="forecast">106.2%</td>

      

or

<td class="forecast"></td>

      

And I want to get what is inside, it could be something like a number, or it could be nothing else, not even an empty space.

I have the following regex part:

<td class=\"forecast\">\\s*(.+?)\\s*</td>

      

It works when there is content inside the HTML cell, but if there is nothing, it gets the next piece of HTML code.

Does anyone know how to solve this?

+3


source to share


1 answer


Just change (.+?)

to (.*?)

.

  • +

    = One or More
  • *

    = zero or more


Added: Regexr

+5


source







All Articles