FsVerbalExpressions
The FsVerbalExpressions
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 FsVerbalExpressions
Introduction
The FsVerbalExpressions
library brings a composable regular expression experience to F#.
FsRegEx
- Module contains composable functions representing all availableRegex
functionality (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
Regex
special collections for better composability (but sacrificing lazy match evaluation and timeout support).Short-cut functions like
capture
on group name make common multi-step processes a single function.FsMatch
- A composable F# wrapper type overSystem.Text.RegularExpressions.Match
.FsGroup
- A composable F# wrapper type overSystem.Text.RegularExpressions.Group
.VerbEx
- A composable F# wrapper type overSystem.Text.RegularExpressions.Regex
for natural language regular expression composition.Basic functional operations on
VerbEx
(exists
,fold
,foldBack
,iter
, andmap
), among other composable functions.-
VerbEx
speciall 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. A future release may include matches returned as a lazy list.
Better F# Composition
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
|
Short-cut common procedures to a single function
1: 2: 3: 4: 5: 6: 7: 8: |
|
Natural Language Regular Expressions
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: |
|
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: |
|
A comparison of using Regex natively, and Verbex 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 desctriptive Verbal Expressions:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
Documentation
FsVerbalExpressions 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
FsVerbalExpressions
natural language syntax and many more usage examples.For enhanced debugging and API documentation experience, FsVerbalExpressions implements SourceLink
Versioning
FsVerbalExpressions 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
FsVerbalExpressions 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 and Verbal Expressions
FsVerbalExpressions 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 FsVerbalExpressions
Full name: Index.carRegExp
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Full name: FsVerbalExpressions.FsRegEx.matches
from Microsoft.FSharp.Collections
Full name: Microsoft.FSharp.Collections.Array.map
Full name: Microsoft.FSharp.Collections.Array.iter
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Full name: Index.groupNumberRegExp
Full name: Index.groupNumberName
Full name: FsVerbalExpressions.FsRegEx.capture
from FsVerbalExpressions
Full name: Index.allXs
type VerbEx =
new : unit -> VerbEx
new : regularExpression:string -> VerbEx
new : regexOptions:RegexOptions -> VerbEx
new : regularExpression:string * regexOptions:RegexOptions -> VerbEx
new : regularExpression:string * regexOptions:RegexOptions * matchTimeout:TimeSpan -> VerbEx
member Capture : input:string -> string -> string
member GroupNameFromNumber : n:int -> string option
member GroupNames : unit -> string array
member GroupNumberFromName : groupName:string -> int option
member GroupNumbers : unit -> int array
...
Full name: FsVerbalExpressions.VerbalExpression.VerbEx
--------------------
new : unit -> VerbEx
new : regexOptions:RegexOptions -> VerbEx
new : regularExpression:string -> VerbEx
new : regularExpression:string * regexOptions:RegexOptions -> VerbEx
new : regularExpression:string * regexOptions:RegexOptions * matchTimeout:System.TimeSpan -> VerbEx
Full name: Index.verbEx
from FsVerbalExpressions
Full name: FsVerbalExpressions.CommonVerbEx.Email
Full name: FsVerbalExpressions.VerbalExpression.verbExOrVerbEx
| None = 0
| IgnoreCase = 1
| Multiline = 2
| ExplicitCapture = 4
| Compiled = 8
| Singleline = 16
| IgnorePatternWhitespace = 32
| RightToLeft = 64
| ECMAScript = 256
| CultureInvariant = 512
Full name: System.Text.RegularExpressions.RegexOptions
Full name: FsVerbalExpressions.CommonVerbEx.Url
Full name: Index.foundEmail
Full name: FsVerbalExpressions.VerbalExpression.isMatch
Full name: Index.foundUrl
Full name: Index.foundAllXs
Full name: Index.groupName
Full name: FsVerbalExpressions.VerbalExpression.add
Full name: FsVerbalExpressions.VerbalExpression.beginCaptureNamed
Full name: FsVerbalExpressions.VerbalExpression.any
Full name: FsVerbalExpressions.VerbalExpression.repeatPrevious
Full name: FsVerbalExpressions.VerbalExpression.endCapture
Full name: FsVerbalExpressions.VerbalExpression.then'
Full name: FsVerbalExpressions.VerbalExpression.capture
Full name: Index.TestConnString
Full name: Index.databaseFromRegex
type Regex =
new : pattern:string -> Regex + 1 overload
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 Matches : input:string -> MatchCollection + 1 overload
member Options : RegexOptions
member Replace : input:string * replacement:string -> string + 5 overloads
...
Full name: System.Text.RegularExpressions.Regex
--------------------
Regex(pattern: string) : unit
Regex(pattern: string, options: RegexOptions) : unit
Regex.Match(input: string, pattern: string, options: RegexOptions) : Match
Full name: Index.databaseFromVerbEx
Full name: Index.databaseFromVerboseVerbEx
Full name: FsVerbalExpressions.VerbalExpression.anyOf