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?
It is possible, but the resulting regex is pretty poor in terms of readability and maintainability.
^(?:[^\.\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:
^
- start of string/line(?:[^\.\n]|\.(?:$|[^h\n]|h(?:$|[^t\n]|t(?:$|[^m\n]|m(?:$|[^l\n])))))*
- matches anything that does not contain .html
build
- literally that string(?:[^\.\n]|\.(?:$|[^h\n]|h(?:$|[^t\n]|t(?:$|[^m\n]|m(?:$|[^l\n])))))*
- same as before$
- end of string/line