I want to convert some VB.NET code for regular expression to F#.
The following code works in VB.NET:
Dim regOpts As RegexOptions = RegexOptions.IgnoreCase Or RegexOptions.Singleline
Dim r As New Regex("<a[^>]*href\s*=\s*""?(?<HRef>[^"">\s]*)""?[^>]*>", regOpts)
But the corresponding code in F# can not get complied:
open System.Text.RegularExpressions
let regOpts: RegexOptions = RegexOptions.IgnoreCase ||| RegexOptions.Singleline
let reg = new Regex("<a[^>]*href\s*=\s*""?(?<HRef>[^"">\s]*)""?[^>]*>", regOpts)
I got the compiler error:
Error: This value is not a function and cannot be applied
I believe F# does NOT recognize the double quote inside double quote, but for VB.NET, it is OK, my code work correctly. Please show me how to modify the F# code, so it can work.
Just escape the
"as\"as described here, instead of the VB.NET escape (that doubles them).Though a better option might be to change it to a verbatim string literal: