正则表达式排除不能与inotifywait一起使用的非golang文件

Below are the regex for filtering out all the non go files (i.e those with '.go' extension)

^([\S]*[^.][^g][^o]|[\S]*.[^g].|[\S]*..[^o]$|[\S]*[^.]..|[\S]{1,2})$

^([^.]*)($|[.]($|[\S]$|g[^o]$|[^g]o$|[^g][^o]$|([\S]+)\.($|.$|g[^o]$|[^g]o$|[^g][^o]$|[^.]{3,}$)|[^.]{3,}$))

You can test them here (click on try it 'Go' in the menu below the regex)

http://fiddle.re/80kvh6

http://fiddle.re/mhv1h6

While they seem to work correctly in go but not with inotifywait's exclude filter (which uses posix ERE format)

I am trying to setup a "watch and reload" task in my Makefile for a golang project. Also i am assuming file or folders names dont have spaces.

You may use

\.[^.][^.][^.]+$|\.[^.][^o]$|\.[^g][^.]$|\.[^.]$

See demo

Or if you can group:

\.([^.][^.][^.]+|[^.][^o]|[^g][^.]|[^.])$

See demo

See explanation:

  • \. - a literal dot
  • ([^.][^.][^.]+|[^.][^o]|[^g][^.]|[^.]) - a group of alternatives:
    • [^.][^.][^.]+ - 2 characters other than . and 1 or more characters other than ....
    • [^.][^o] - a character other than a dot and a character other than o...
    • [^g][^.] - a character other than g and a character other than a dot...
    • [^.] - a character other than a dot...
  • $ - right before the end of string.

Got the issue. It seems [:graph:] not \S the class identifier for non-space chars in extended posix. The below is good to go.

^[[:graph:]]*[^.][^g][^o]$|^[[:graph:]]{1,2}$|^[[:graph:]]*.[^g].$|^[[:graph:]]*..[^o]$|^[[:graph:]]*[^.]..$

or even a better one from stribizhev comment [^.][^g][^o]$|^..$|.[^g].$|..[^o]$|[^.]..$