Complex regular expression ... AND OR, negation

684 Views Asked by At

I would like to search files by their content in Total Commander so I want to create a regex, but I cannot find any manual where it would really be explained. My situation is that I need something like this:

fileContains("<html>") && fileContains("{myVariable1}") && fileNotContains("<script>")

I can write cca this:

(<html>)+
({myVariable1})+
(<script>){0} ... but this does not work for me

And I cannot put it all together. Any ideas, please? Or do you have a link to an excellent regex explanation?

1

There are 1 best solutions below

1
Scott Weaver On

try this regex:

(?=.*\{myVariable1\})(?=.*<html>)(?!.*<script>)

it's just 3 lookaheads in a row. one of those is a negative lookahead. Note the "single line" modifier to enable 'dot matches newline'.

edit (per comment): I guess Total Commander's regex engine does not support lookarounds at all. While you could combine two positive lookaheads into an equivalent 'consuming' pattern with something like this untested regex: (.*(\{myVariable1\}|<html>)){2}, you cannot include the 'negated search' within a single regex unless you have a legitimate regex engine.

You could try this Total Commander regex plug-in:

A RegEx content plug-in with Unicode support - based on Perl Compatible Regular Expressions (PCRE) library. This plug-in may replace TC's RegEx engine for file content