Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Regular Expression - Something or Nothing

Tags:

c#

regex

I have two types of possible lines to get information from:

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

or

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

And I want to get what is inside, it can be something, like a number, or it can be exactly nothing, not even a white space.

I have the following piece of regular expression:

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

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

Does someone knows how to solve this?

like image 471
f4d0 Avatar asked Sep 12 '26 02:09

f4d0


1 Answers

Just change the (.+?) to (.*?).

  • + = One or More
  • * = Zero or More

Added: Regexr

like image 149
Orel Eraki Avatar answered Sep 13 '26 15:09

Orel Eraki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!