Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created April 19, 2014 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtchepak/11083161 to your computer and use it in GitHub Desktop.
Save dtchepak/11083161 to your computer and use it in GitHub Desktop.
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