vshankara
vshankara

Reputation: 91

How to extract sub strings in lua

I have a string "[testid-1] is locked out / / Subject: / Account Domain: NM /" and I need to extract "testid-1" within the square braces and domain "NM" out of the string using Lua script. I am trying to use the below code with no luck, I have also tried escaping [.

aname=string.match(a,'[(.*)]')

Upvotes: 1

Views: 4324

Answers (2)

vshankara
vshankara

Reputation: 91

Just figured that the escape character in lua is %. This code works fine:

aname=string.match(a,'%[(.*)%]')
adomain=string.match(a,'.*Account Domain: (%a+)')

Upvotes: 1

lhf
lhf

Reputation: 72312

You can do it in a single call:

aname, adomain = a:match('%[(.*)%].*Account Domain:%s*(.-)%s*/')

Upvotes: 2

Related Questions