Search code examples
luapattern-matchinglua-patterns

Lua pattern matching for empty string


after trying and reading Lua's doc on patterns, I couldn't figure it out.

I am using an OBS plugin to activate a source on text document change, and the plugin uses Lua pattern matching. I would like to trigger the source whenver the document is EMPTY and only empty. How can I go about doing this?

Example, using the non-empty pattern match:

enter image description here

Thank you for any help!


Solution

  • Pattern matching an empty string is

    ^$
    

    where

    • ^ - matches the start of string position
    • $ - matches the end of string position.

    That is, start and end of string positions must be the same position in the string.