Search code examples
stringlualua-patterns

How to filter the errormessage in a Lua string


With luasec I recieve the following answer:

blablabla..result="0"><header result="0"><office msgtype="error" msg="Administratie 355140001 bestaat niet." result="0">355140001</office><code>K..blablabla

How can I filter the text between the quotes behind "msg="?

With the function string.find (responsetable,"msg=") I can find the first character, but how can I read the rest of the string until the last quote. (the length of the errormessage is different).


Solution

  • To get the content, use string.match:

    str:match('msg="(.-)"')
    --Administratie 355140001 bestaat niet.
    

    Note that use of - for 0 or more lazy repetitions.