Skip to content

Instantly share code, notes, and snippets.

@stuartpb
Created May 16, 2011 19:47
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 stuartpb/975183 to your computer and use it in GitHub Desktop.
Save stuartpb/975183 to your computer and use it in GitHub Desktop.
Counts the occurrences of a phrase in an RFC
local src = http.request"http://tools.ietf.org/id/draft-ietf-ldapext-ldap-c-api-05.txt"
src = string.gsub(src,[[
Expires: May 2001 -%[Page %d+%]
C LDAP API -C LDAP Application Program Interface -17 November 2000]],"\n")
local function count(pat)
return select(2,string.gsub(src,pat,""))
end
local function plain(str)
return (string.gsub(str,"[^%w%s]","%%%0"))
end
local function overspace(str)
return (string.gsub(str,"%s+","%%s%+"))
end
local function normspace(str)
return (string.gsub(str,"%s+"," "))
end
return select(2,string.gsub(src,overspace(
"[Aa] subsequent call to ldap_result%(%), described below, can be used to obtain the result of the (.-)%."),
function(word) print(normspace(word)) end))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment