Jump to content
Wikipedia The Free Encyclopedia

Module:User:Mr. Stradivarius/String count

From Wikipedia, the free encyclopedia
Module documentation[create] [purge]
You might want to create a documentation page for this Scribunto module.
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
 -- This module counts the number of times a string appears on a given page.

 local p = {}

 local function escapePattern(s)
	-- Escape punctuation in a string so it can be used in a Lua pattern.
	s = s:gsub('%p', '%%%0')
	return s
 end

 function p.count(frame)
	local text = mw.title.new(frame.args.page):getContent()
	local pattern = escapePattern(frame.args.search)
	local temp, count = mw.ustring.gsub(text, pattern, '')
	return count
 end

 return p

AltStyle によって変換されたページ (->オリジナル) /