Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Extending regexes



Hi, 
Zsh has extensions to regular regexes - the ~ and ^ negations. They, as it can be expected from negations that are required by Turing universal machines, introduce a whole new universe of computations over standard regular expressions. For example matching in an AND fashion: 

If [[ ABC == *A*~^*B*~^*C* ]]; then 
  print A,  B and C found
fi 

I think that regexes look pretty limited from this point of view and that pcre extensions went wrong path with the look forward and behind semantics. The typical, common attempts of using regex [^] negation like [^(string)] are simply there in zsh patterns as ^string. 

I've recently used ~ negation in a project to reject a set of known tokens from matching at given position with a great success to match a loose `for` syntax in an zinit-annex-pull extension to zinit that greps and extracts zinit commands from any web page. I cannot see it possible without the extra negation. 

Therefore I thought that it's weird that such an useful feature is missing from the commonly used regex syntax. So maybe an attempt of updating it has sense? Could someone experienced with them like Oliver prepare some white papers to accomplish this? It would be a great event to extend the old regexes with such a great feature like not one, but TWO new negations. 


Messages sorted by: Reverse Date, Date, Thread, Author