I was trying to get a named regular expression working in F# without much luck. Ported to C# and it works. Is there some peculiarity with F# that I’m missing here or is it a bug?
F#
open System.Text.RegularExpressions;;
let regex = new Regex("(?<liveId>WindowsLiveID)|(?<facebook>Facebook)", RegexOptions.Compiled ||| RegexOptions.IgnoreCase);;
let m = regex.Matches("ImWindowsLiveIDOK");;
m.[0].Groups.["liveID"].Success;;
C#
var regex = new Regex("(?<liveId>WindowsLiveID)|(?<facebook>Facebook)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var match = regex.Matches("ImWindowsLiveIDOK");
Console.WriteLine(match[0].Groups["liveId"].Success);
Groups are case sensitive. You have
"liveID"on F#, and"liveId"on C# (note theD).On the first block, there is no group called
liveID, so it fails.