Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a22b3d157eaf5751

Jump to content

Module:User:Mr. Stradivarius/String count

From Wikipedia, the free encyclopedia
-- 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