FSharp.Text.RegexProvider


FSharp.Text.RegexProvider

The FSharp.Text.RegexProvider project contains a type provider for regular expressions.

The library can be installed from NuGet:
PM> Install-Package FSharp.Text.RegexProvider

Example

This example demonstrates the use of the type provider:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
// reference the type provider dll
#r "FSharp.Text.RegexProvider.dll"
open FSharp.Text.RegexProvider

// Let the type provider do its work
type PhoneRegex = Regex< @"(?<AreaCode>^\d{3})-(?<PhoneNumber>\d{3}-\d{4}$)" >


// now you have typed access to the regex groups and you can browse it via Intellisense
PhoneRegex().TypedMatch("425-123-2345").AreaCode.Value

val it : string = "425"

alt text

Note that since version 1.0, generated methods are prefixed by Typed by default. You can disable this behaviour using the parameter noMethodPrefix:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
type MultiplePhoneRegex = Regex< @"\b(?<AreaCode>\d{3})-(?<PhoneNumber>\d{3}-\d{4})\b", noMethodPrefix = true >

// now the generated types are just added as an overload of the existing method name on the `Regex` type
MultiplePhoneRegex().Matches("425-123-2345, 426-123-2346, 427-123-2347")
|> Seq.map (fun x -> x.AreaCode.Value)
|> List.ofSeq

val it : string list = ["425"; "426"; "427"]

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding new public API, please also consider adding samples that can be turned into a documentation. You might also want to read library design notes to understand how it works.

The library is available under Public Domain license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

namespace FSharp
namespace FSharp.Text
namespace FSharp.Text.RegexProvider
type PhoneRegex = Regex<...>

Full name: Index.PhoneRegex
type Regex =
  inherit Regex
  member Options : RegexOptions
  member RightToLeft : bool
  val capnames : Hashtable
  val caps : Hashtable
  val capsize : int
  val capslist : string []
  val factory : RegexRunnerFactory
  val pattern : string
  val roptions : RegexOptions
  ...

Full name: FSharp.Text.RegexProvider.Regex
type MultiplePhoneRegex = Regex<...>

Full name: Index.MultiplePhoneRegex
module Seq

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val x : Regex<...>.MatchType5
property Regex<...>.MatchType5.AreaCode: System.Text.RegularExpressions.Group


Gets the "AreaCode" group from this match
property System.Text.RegularExpressions.Capture.Value: string
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member GetSlice : startIndex:int option * endIndex:int option -> 'T list
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val ofSeq : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.List.ofSeq
Fork me on GitHub