« Module:IdentifierRACJ » : différence entre les versions

Nouvelle mouture
Nouvelle version bogue capture en double
Ligne 3 : Ligne 3 :
function p.extraireNoDeDecision(frame)
function p.extraireNoDeDecision(frame)
     local texte = frame.args[1] or ""
     local texte = frame.args[1] or ""
     local identifiant = string.match(texte, "(%d%d%-500%d%d%d%d)")
 
    -- 1. Match un identifiant de type dd-500xxxx (avec frontières)
     local identifiant = string.match(texte, "(%f[%d]%d%d%-500%d%d%d%d%f[%D])")
     if identifiant then
     if identifiant then
         return identifiant
         return identifiant
     end
     end
     identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d)")
 
     return identifiant or ""
     -- 2. Match un identifiant de type dd-ddddddd UNIQUEMENT s’il n’est pas suivi d’un -ddd
    for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
        local fullMatch = string.match(texte, id .. "%-%d%d%d")
        if not fullMatch then
            return id
        end
    end
 
     return ""
end
end