Created
May 16, 2011 19:47
-
-
Save stuartpb/975183 to your computer and use it in GitHub Desktop.
Counts the occurrences of a phrase in an RFC
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
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