Improve the regex:
- Use Perl type regex in grep to remove duplication. Previously there
was 2 alsmost identical regex, one posix compliant for egrep and one
Perl compliant for python re.
- Exclude the test folder from the source path rather than subtracting
its matching output
This improvements make the -h now detectable; it is added to the
undocumented exceptions.
Inspired from core PR12820.
Note that GNU grep is used instead of git grep to allow for
multiline regex (required due to our code format).