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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tdmailbox@yahoo.com

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

    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_n um.*?>(.*?)</td>",
    RegexOptions.Ig noreCase);

    string unit_num = reg_unit_num.Ma tch(strHTMLPage ).Result("$1");

  • Michael C#

    #2
    Re: Regular Expression Regex/Match fails if regular expression returns a null

    Regex reg_unit_num = new Regex("L_unit_n um.*?>(.*?)</td>",
    RegexOptions.Ig noreCase);
    Match m = reg_unit_num.Ma tch(strHTMLPage );
    string unit_num = "";
    if (m.Success)
    {
    unit_num = m.Result("$1");
    }

    <tdmailbox@yaho o.com> wrote in message
    news:1117499980 .926488.50760@f 14g2000cwb.goog legroups.com...
    [color=blue]
    >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_n um.*?>(.*?)</td>",
    > RegexOptions.Ig noreCase);
    >
    > string unit_num = reg_unit_num.Ma tch(strHTMLPage ).Result("$1");
    >[/color]


    Comment

    Working...