open System.Text.RegularExpressions
let (|Regex|_|) pattern input =
let m = Regex.Match(input, pattern) in
if m.Success then Some(List.tail [ for g in m.Groups -> g.Value ])
let phone = "(555) 555-5555"
| Regex @"\(([0-9]{3})\)[-. ]?([0-9]{3})[-. ]?([0-9]{4})" [ area; prefix; suffix ]->
printfn "Area: %s, Prefix: %s, Suffix: %s" area prefix suffix
let matchwordsplit(address: string, pattern, param) =
let splitmot = address.Split(' ')
let regexmatch(mot, pattern) =
|Regex pattern result -> result.Head
let listmatchregex = splitmot |> Array.map (fun mot -> regexmatch(mot, pattern)) |> List.ofArray
let listmot = listmatchregex |> List.choose( fun mot -> accmot("",mot))
if listmot.Length >=1 then
|"last" -> [listmot.Item(listmot.Length - 1)]
|"first" -> [listmot.Item(0)]
let matchwords(input: string, pattern) =
let regexmatch(mot, pattern) =
|Regex pattern result -> result
regexmatch(input, pattern)
let l = matchwordsplit("Edouard moureaux1203 (PO) (ER) (FRANCE)",@"(\w+\b)\)","all")
let catchemail = matchwords("'rez f edouard2.moureaux@gmail.com (FRANCE)", @"(\w+\.?\w+@\w+\.\w{2,})")
let catchtel = matchwords("03.02-40.6363", @"(\d{2})?\.?\s?(\d{2})?.?\s?(\d{2}).?\s?(\d{2}).?\s?(\d{2}).?\s?(\d{2}).?\s?(\d{2})")
let catchsalutation = matchwords("Mr. Edouard Moureaux Suite", @"(Mr\s|Mr.\s|M\s|Mme\s)?(\w+\s)?(\w+\b)\s?(\w+\b)?")
printlist catchsalutation