FsRegEx
The FsRegEx library provides composable F# functionality for nearly all the capabilites of the .NET Regex class, supporting uniform pipe forward |> composability and all Regex features except timeouts. Optionally you can compose F# verbal expressions in natural language. Lazy evaluation ensures natural language composition imposes no performance penalty.
PM> Install-Package FsRegEx
Introduction
The FsRegEx library brings a composable regular expression experience to F#.
Composable functions representing all available
Regexfunctionality (except timeouts) with the target input string uniformly the last parameter to better support pipe forward|>composition and partial application.Collections returned as F# arrays rather than
Regexspecial collections for better composability (but sacrificing lazy match evaluation and timeout support).-
Short-cut functions like
captureon group name make common multi-step processes a single function.FsRegEx- A composable F# wrapper type overSystem.Text.RegularExpressions.Regexfor natural language regular expression composition.
FsMatch- A composable F# wrapper type overSystem.Text.RegularExpressions.Match.FsGroup- A composable F# wrapper type overSystem.Text.RegularExpressions.Group.Basic functional operations on
FsRegEx(exists,fold,foldBack,iter, andmap), among other composable functions.-
FsRegExspeciall collections are returned as arrays. This does lose the advantange of lazy match evaluation the special collections provide. The underlying object can always be returned from the wrapper.
Better F# Composition
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: |
|
Short-cut common procedures to a single function
1: 2: 3: 4: 5: 6: 7: 8: |
|
Natural Language Regular Expressions
The library also provides the composable Verbal Expressions language for constructing simple regular expressions in a readable fashion.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: |
|
A comparison of using Regex natively, and Verbal Expressions to retrieve the database parameter from a connection string:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: |
|
This example shows the more verbose and descriptive Verbal Expressions:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
Documentation
FsRegEx comes with comprehensive API documentation and a tutorial.
API Reference contains documentation for all types, modules, and functions in the library.
F# Verbal Expressions Tutorial contains further explanation of the natural language DSL syntax and many more usage examples.
Versioning
FsRegEx adheres to Semantic Versioning. So long as the project is pre-1.0.0 minor versions may be breaking. Once the project reaches 1.0.0 minor enhancements will be backwards-compatible.
Contributing and copyright
FsRegEx is hosted on GitHub where you can report issues, fork the project, and submit pull requests, so long as pull requests:
- include excellent unit test coverage
- include correct intellisense documentation
- adhere to the concepts of composability
FsRegEx 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.
from Microsoft.FSharp.Collections
type Regex =
new : pattern:string -> Regex + 2 overloads
member GetGroupNames : unit -> string[]
member GetGroupNumbers : unit -> int[]
member GroupNameFromNumber : i:int -> string
member GroupNumberFromName : name:string -> int
member IsMatch : input:string -> bool + 1 overload
member Match : input:string -> Match + 2 overloads
member MatchTimeout : TimeSpan
member Matches : input:string -> MatchCollection + 1 overload
member Options : RegexOptions
...
--------------------
Regex(pattern: string) : Regex
Regex(pattern: string, options: RegexOptions) : Regex
Regex(pattern: string, options: RegexOptions, matchTimeout: System.TimeSpan) : Regex
Regex.Match(input: string, pattern: string, options: RegexOptions) : Match
Regex.Match(input: string, pattern: string, options: RegexOptions, matchTimeout: System.TimeSpan) : Match