ENH: support negated regular expressions (#2283)

- extendes the prefix syntax to handle '!' values.

  For example,  "(?!).*processor.*" or "(?!i)inlet.*"
This commit is contained in:
Mark Olesen
2021-12-03 15:32:54 +01:00
parent 49e26dd7d2
commit e09298092d
8 changed files with 478 additions and 188 deletions

View File

@ -252,12 +252,16 @@ void testExpressions(const UList<regexTest>& tests)
}
else if (re.search(str))
{
Info<< "partial match";
Info<< "partial";
}
else
{
Info<< "false";
}
if (re.negated())
{
Info<< " (negated)";
}
Info<< endl;
}
catch (const Foam::error& err)
@ -329,6 +333,15 @@ int main(int argc, char *argv[])
}
#endif
Info<< "sizeof std::regex: " << sizeof(std::regex) << nl;
Info<< "sizeof regex C++11: " << sizeof(regExpCxx) << nl;
#ifndef _WIN32
Info<< "sizeof regex POSIX: " << sizeof(regExpPosix) << nl;
#endif
Info<< "sizeof word: " << sizeof(Foam::word) << nl;
Info<< "sizeof wordRe: " << sizeof(Foam::wordRe) << nl;
Info<< "sizeof keyType: " << sizeof(Foam::keyType) << nl;
if (!args.count({"cxx", "posix"}))
{
args.setOption("cxx");

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2106 |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -12,6 +12,8 @@
(
( true "(U|k|epsilon)" "U" )
( false "(U|k|epsilon)" "alpha" )
( true "(?!)(U|k|epsilon)" "alpha" )
( true "(?! *&)(U|k|epsilon)" "alpha" ) // Ignore unknown content
( true "ab.*" "abc" )
( true ".*" "abc" )