Simple example - how to validate hexadecimal input
Suppose we want to use Regex as a format validator of an input string. We will use the widely known definition.
Throughout history, there have been various ways to indicate a hex string. In the 1970's-1990's, a hex number was indicated with a leading '$' ie "$A0", but nowadays, a hex-number is notated with a leading '0x', ie "0xF5"
We will support both notations, and accept bytes (8-bit) and words (16-bit), and we don't care about upper/lower-case.
The patterns are composed from the ground up:.
- Define the alphabet;
- Define the value-format;
- Define the format of notation style in conjunction wih the value-format;
- Put it all together;
- Create a validation function which returns the hex-value when the input is valid.
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: 33: 34: 35: 36: 37: 38: 39: 40: 41: |
|
module ReggerIt
namespace System
namespace System.Text
namespace System.Text.RegularExpressions
val HexDigit : RexPatt
val Between : char -> char -> RexPatt
val hexByte : RexPatt
val RepeatExact : int -> RexPatt -> RexPatt
val hexWord : RexPatt
val formatHexByteAntique : RexPatt
val Plain : string -> RexPatt
val NamedGroup : string -> RexPatt -> RexPatt
val formatHexWordAntique : RexPatt
val formatHexByte : RexPatt
val formatHexWord : RexPatt
val pattern : RexPatt
val validate : s:string -> string option
val s : string
val parse : Match
Multiple items
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
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) : Match
Regex.Match(input: string, pattern: string, options: RegexOptions) : Match
Regex.Match(input: string, pattern: string, options: RegexOptions, matchTimeout: System.TimeSpan) : Match
Regex.Match(input: string, pattern: string, options: RegexOptions) : Match
Regex.Match(input: string, pattern: string, options: RegexOptions, matchTimeout: System.TimeSpan) : Match
module Convert
from ReggerIt
from ReggerIt
val ToFullstringPattern : RexPatt -> string
type RegexOptions =
| None = 0
| IgnoreCase = 1
| Multiline = 2
| ExplicitCapture = 4
| Compiled = 8
| Singleline = 16
| IgnorePatternWhitespace = 32
| RightToLeft = 64
| ECMAScript = 256
| CultureInvariant = 512
| None = 0
| IgnoreCase = 1
| Multiline = 2
| ExplicitCapture = 4
| Compiled = 8
| Singleline = 16
| IgnorePatternWhitespace = 32
| RightToLeft = 64
| ECMAScript = 256
| CultureInvariant = 512
field RegexOptions.IgnoreCase: RegexOptions = 1
property Group.Success: bool with get
union case Option.Some: Value: 'T -> Option<'T>
property Match.Groups: GroupCollection with get
union case Option.None: Option<'T>
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IReadOnlyList<'T>
interface IReadOnlyCollection<'T>
interface IEnumerable
interface IEnumerable<'T>
member GetReverseIndex : rank:int * offset:int -> int
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
...
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IReadOnlyList<'T>
interface IReadOnlyCollection<'T>
interface IEnumerable
interface IEnumerable<'T>
member GetReverseIndex : rank:int * offset:int -> int
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
...
val iter : action:('T -> unit) -> list:'T list -> unit
val input : string
val v : string
val printfn : format:Printf.TextWriterFormat<'T> -> 'T