Reputation: 31
I have a Cisco ASA 8.4 VPN Concentrator. I am trying to use Lua to extract digits from a certificate string coming in and use them in a LDAP lookup with AD for authorization. I found a string that works...sometimes.
The string comes in with the format:
LAST_NAME.FIRST_NAME.MIDDLE_NAME.1234567890
My LDAP only wants to see the digits and @domainname. The script I am currently us is: return string.gsub(cert.subject.cn, "^(%w+)%.(%w+)%.(%w+)%.(%w+)$", "%4@domain")
This script works fine in most cases (80-90% of the time). When it doesn't work is when people have no middle name, 4 names instead of 3, etc.
My question is how can I get it to output only the 10 digits, regardless of what comes before it. Seems too easy with a return string.match, but so far I can't get it to work. Any ideas?
Upvotes: 3
Views: 1402
Reputation: 122493
You can use the pattern .*(%d%d%d%d%d%d%d%d%d%d)$
:
local str = 'LAST_NAME.FIRST_NAME.MIDDLE_NAME.1234567890'
print(str:match('.*(' .. ('%d'):rep(10) .. ')$'))
or .*(%d+)$
if the number of digits is always 10.
If the 10 digits is always the last 10 characters, this works:
print(str:sub(-10, -1))
Upvotes: 4