Tutorial: F# Verbal Expressions
The VerbalExpressions
module includes the VerbEx
type which wraps the familiar .NET RegEx
in a type with useful functional members.
Multiple constructors start with a regular expression in the constructor.
1:
|
|
Beyond this the module is an experimental DSL that allows you to compose regular expressions in natural language
using the immutable VerbEx
type. The remainder of this tutorial is concerned with the experimental DSL which is, frankly, not that practical.
For practical examples of using the core FsRegEx
module for composability, see the following examples:
Verbal Expressions DSL
You can compose values of the VerbEx type with the |> operator, including creating a new regular expression by logical or on 2 existing VerbExs.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: |
|
Natural language composition consists of building up a new VerbEx from an old by functions which append special characters, groups, modifiers, and other attributes of the regular expression language.
function : 'T -> VerbEx -> VerbEx
See the API documentation for all the regular expression functions available.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: |
|
You do not have to worry about escaping special characters in your regular expression.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: |
|
Sometimes you may need more power than the natural language provides, or you just need to include a snippet of native regular expression. The add function lets you do that.
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
VerbExs posses all the power of the .Net RegEx class in a composable form.
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: 31: 32: |
|
VerbEx comes with first class support for unicode, including unicode general categories and .Net extension blocks.
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
Full name: Tutorial.verbEx
Full name: Tutorial.v
from FsVerbalExpressions
Full name: FsVerbalExpressions.CommonVerbEx.Email
from FsVerbalExpressions
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: Tutorial.foundEmail
Full name: FsVerbalExpressions.VerbalExpression.isMatch
Full name: Tutorial.foundUrl
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Full name: Tutorial.foundFromGithub
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: FsVerbalExpressions.VerbalExpression.startOfLine
Full name: FsVerbalExpressions.VerbalExpression.something
Full name: FsVerbalExpressions.VerbalExpression.then'
Full name: FsVerbalExpressions.VerbalExpression.endOfLine
Full name: FsVerbalExpressions.VerbalExpression.isMatch
Full name: Tutorial.foundSomethingSpecial
Full name: FsVerbalExpressions.VerbalExpression.anything
Full name: Tutorial.foundSpecialInMultiline
Full name: FsVerbalExpressions.VerbalExpression.add
Full name: Tutorial.n
Full name: FsVerbalExpressions.VerbalExpression.word
Full name: FsVerbalExpressions.VerbalExpression.matches
Full name: Tutorial.betterFormat
Full name: FsVerbalExpressions.VerbalExpression.or'
Full name: FsVerbalExpressions.VerbalExpression.replace
Full name: Tutorial.groupName
Full name: FsVerbalExpressions.VerbalExpression.beginCaptureNamed
Full name: FsVerbalExpressions.VerbalExpression.any
Full name: FsVerbalExpressions.VerbalExpression.repeatPrevious
Full name: FsVerbalExpressions.VerbalExpression.endCapture
Full name: FsVerbalExpressions.VerbalExpression.capture
Full name: FsVerbalExpressions.VerbalExpression.unicodeCategory
| LetterUppercase
| LetterLowercase
| LetterTitlecase
| LetterModifier
| LetterOther
| Letter
| MarkNonspacing
| MarkSpacingCombining
| MarkEnclosing
| Mark
...
override ToString : unit -> string
Full name: FsVerbalExpressions.UniCodeGeneralCategory