Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Deformat: Difference between revisions

From Trackmania Wiki
Created page with "-- Function: Removes dollar-sign based formatting codes from a string. local p = {} function p.run(frame) -- Get the input text from the first argument of the template call. -- Defaults to an empty string if no argument is provided. local text = frame.args[1] or '' -- Pattern: \$(?:(\$)|[0-9a-fA-F]{2,3}|[lh]\[.*?\]|[lh]\[|.) local pattern = '\\$(?:(\\$)|\\[0-9a-fA-F]{2,3}|\\[lh]\\[.*?\\]|\\[lh]\\[|.)' -- Replace every match of the pattern..."
(No difference)

Revision as of 22:08, 20 August 2025

Documentation for this module may be created at Module:Deformat/doc

-- Function: Removes dollar-sign based formatting codes from a string.

local p = {}

function p.run(frame)
    -- Get the input text from the first argument of the template call.
    -- Defaults to an empty string if no argument is provided.
    local text = frame.args[1] or ''

    -- Pattern: \$(?:(\$)|[0-9a-fA-F]{2,3}|[lh]\[.*?\]|[lh]\[|.)
    local pattern = '\\$(?:(\\$)|\\[0-9a-fA-F]{2,3}|\\[lh]\\[.*?\\]|\\[lh]\\[|.)'
    
    -- Replace every match of the pattern with an empty string.
    local deformattedText = mw.ustring.gsub(text, pattern, '')

    return deformattedText
end

return p