Created
June 5, 2011 04:32
-
-
Save nagat01/1008649 to your computer and use it in GitHub Desktop.
F# : Regex.Match, Regex.Matches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
http://msdn.microsoft.com/en-us/library/30wbz966(v=vs.71).aspx#Y470 | |
Match : finds first occurrence | |
Match.Success : is match succeed? | |
Match.Groups : collection of captured groups | |
Matches : store every non-overlapping occurrences to Item | |
Matches.Item : indexed property of mathed string | |
*) | |
open System | |
open System.Text.RegularExpressions | |
let matchSample r m = | |
let r = new Regex(r) | |
let m1 = r.Match m | |
printfn "m.Groups = %A" m1.Groups | |
printfn "m.Captures = %A" m1.Captures | |
let ms = r.Matches m | |
printfn "ms.Count = %A" ms.Count | |
for i in 0..ms.Count-1 do | |
printfn "ms.Item.[%d] = %A" i <| ms.Item i | |
matchSample "a(bc)d(e(fg))h" "abcdefgh_abcdefgh" | |
(* Result : | |
m.Groups = seq [abcdefgh; bc; efg; fg] | |
m.Captures = seq [abcdefgh] | |
ms.Count = 2 | |
ms.Item.[0] = abcdefgh | |
ms.Item.[1] = abcdefgh | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment