In my project, I need to extract some parameters from a settings file. Below is a section of the line that I am reading, the parameter I need to extract is the Program Prefix.
... ProgramPrefix="" ReceiveTimeout="80000" ...
I need to extract what is between the double quotes for ProgramPrefix. The problem is that in-between these quotes can be any alphanumeric character, symbol, space, or no character at all.
Below is my current solution for extracting any character before the second double-quote, the problem doesn't work for the case of anything being between the double quotes
EOPdefL = string.find(line,"ProgramPostfix=")
EOPdef = string.match(line,'([^"]+)',EOPdefL+16)
When there is nothing in-between the double quotes the output for EOPdef is:
EOPdef = ReceiveTimeout=
I would like EOPdef to just return an empty string if there are no characters.
EOPdef = ""
EDIT: lhf and Piglet provided a working resolution. The character class to capture 0 or more characters in between double quotes is the following:
'"(.-)"'
Implementing this character class into my solution results in the following code:
SOPdefL = string.find(line,"ProgramPrefix=")
SOPdef = string.match(line,'"(.-)"',SOPdefL+14)