Regular Expression Regex/Match fails if regular expression returns a null

  • Thread starter Thread starter tdmailbox
  • Start date Start date
T

tdmailbox

I have the following regular expression. It works fine if the regex
code returns a match. However if not the .match code fails.

How can I code this so that it skips the match if the regular
expression does not find anything?


Regex reg_unit_num = new Regex("L_unit_num.*?>(.*?)</td>",
RegexOptions.IgnoreCase);

string unit_num = reg_unit_num.Match(strHTMLPage).Result("$1");
 
Regex reg_unit_num = new Regex("L_unit_num.*?>(.*?)</td>",
RegexOptions.IgnoreCase);
Match m = reg_unit_num.Match(strHTMLPage);
string unit_num = "";
if (m.Success)
{
unit_num = m.Result("$1");
}
 
Back
Top