I have a HTML input that have three patterns like this:
Pattern one
</div>
<div class="myclass">
Pattern two
</div>
<p class="ProductMeta">29-06-2011</p>
<div class="myclass">
Pattern trhee
</div>
<p class="ProductMeta">29/06/2011</p>
<div class="myclass">
I’m trying to create a RegEx that can catch the tree dates: empty, with dashes and with slashes. I think i need some kind of nested groups, but can’t make it work.
This is the RegEx I’ve created:
Regex r = new Regex(
@"src=""</div>\s+<p class=""ProductMeta"">([\d\/\-]+)"
, RegexOptions.Compiled | RegexOptions.IgnoreCase);
And tried the following to make the group optional:
Regex r = new Regex(
@"src=""</div>[\s+<p class=""ProductMeta"">([\d\/\-]+)]?"
, RegexOptions.Compiled | RegexOptions.IgnoreCase);
Can anyone help me?
The console test does the following to print on screen:
foreach (Match m in mcl)
{
Console.WriteLine(m.Groups[1].Value.Replace("-","/") + " - " + m.Groups[5].Value);
}
Console.Read();
Thanks.
You can’t make the
[]‘s an optional group. Only()can be optional.