regexregex-lookaroundsunison

Regex alternative to negative lookahead


I want to match all paths that include the keyword build unless they also contain .html

Here is a working regex that uses negative lookahead: https://regexr.com/4msck

I am using regex for path matching in unison which does not support negative lookahead. How can I replicate the functionality of the above regex without negative lookahead?


Solution

  • It is possible, but the resulting regex is pretty poor in terms of readability and maintainability.

    http://regexr.com/4mst1

    ^(?:[^\.\n]|\.(?:$|[^h\n]|h(?:$|[^t\n]|t(?:$|[^m\n]|m(?:$|[^l\n])))))*build(?:[^\.\n]|\.(?:$|[^h\n]|h(?:$|[^t\n]|t(?:$|[^m\n]|m(?:$|[^l\n])))))*$
    

    Explanation: