Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created Apr 19, 2014
Embed
What would you like to do?
public IEnumerable<string> GetSamples(string s) {
var re = @"\{%\s*(?<tag>\w+)\s*\%\}(?<contents>(?s:.*?))\{%\s*end\1\s*%\}";
return Regex.Matches(s, re)
.Cast<Match>()
.Where(m => m.Groups["tag"].Value == "sample")
.Select(m => m.Groups["contents"].Value.Trim());
}
let getSamples s : string seq =
let re = @"\{%\s*(?<tag>\w+)\s*\%\}(?<contents>(?s:.*?))\{%\s*end\1\s*%\}"
Regex.Matches(s, re)
|> Seq.cast<Match>
|> Seq.filter (fun m -> m.Groups.["tag"].Value = "sample")
|> Seq.map (fun m -> m.Groups.["contents"].Value.Trim())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment