How to get only a part of a string from a pattern?

2

I have a string in Lua language. I want to get only the filename part through match ( 403.htm.en ).

Example:

var=[[Content-Disposition: attachment; filename="403.htm.en"
     Content-Type: text/plain; name='403.htm.en'
     Content-Transfer-Encoding: BASE64
    ]]
filename = string.match(var,"filename(.+)")
print("filename", filename)
    
asked by anonymous 30.07.2015 / 18:59

1 answer

2

I do not know the most reliable form but this works:

var=[[Content-Disposition: attachment; filename="403.htm.en"
     Content-Type: text/plain; name='403.htm.en'
     Content-Transfer-Encoding: BASE64
    ]]
filename = string.match(var,"filename=\"(.+)\"")
print("filename = ", filename)

See running on ideone .

You had to put the delimiters wherever you want the text to begin and end.

    
31.07.2015 / 01:04