Module:ConditionalExtract

From Sun Haven Wiki
Jump to navigation Jump to search

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

local p = {}

function p.extract(frame)
    local value = frame.args[1]
    local afterLeft, beforeRight
    if string.find(value, "«") then
        afterLeft = mw.ustring.match(value, "«(.-)»")
        if afterLeft then
            return afterLeft
        end
    end
    -- If there's no match for "«...»" or "«" is not present, find what's after "»"
    afterRight = mw.ustring.match(value, "»(.*)")
    if afterRight then
        return afterRight
    else
        return value -- Default return if no "»" found
    end
end

return p