lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Monday, March 3, 2014, Philipp Janda <> wrote:
Am 03.03.2014 19:34 schröbte Andrew Starks:
I'm having trouble finding a pattern that works for finding an
unescaped quote in a string. So:

[[\']] should not match

[[']] should match

I can get it to work with  '([^%\\]")' , except at the beginning of the string.

You could put a dummy character at the beginning of the string ...

My suggestion:

    local function qfind( s )
      local ok, a, b = string.match( " "..s, "[^\\](\\*)%1()[\"']()" )
      if ok then
        return a-1, b-1
      return nil

(But if you write an extra function for matching, you could as well try the two different patterns and save the temporary string ...)



Thank you, both. Enrico's solution is the one that I had in place. 

I had failed to grasp that "any character that is not" means that there must be a character.