Snakemake wildcard constraints reject too much I have the following two rules:
rule extract:
    input: &quot;data/{dir}/{file}.gz&quot;
    output: &quot;data/{dir}/{file,^.*(?&lt;!\.gz)$}&quot;
    conda: &quot;config/conda-extract-env.yml&quot;
    shell: &quot;cd 'data/{wildcards.dir}'; gunzip -k {wildcards.file}.gz&quot;

rule extract_dot:
    input: &quot;data/{dir}/wtdbg2.3.dot.gz&quot;
    output: &quot;data/{dir}/wtdbg2.3.dot&quot;
    conda: &quot;config/conda-extract-env.yml&quot;
    shell: &quot;cd 'data/{wildcards.dir}'; gunzip -k wtdbg2.3.dot.gz&quot;

The second one is actually a hack because the first does not work on files named wtdbg2.3.dot.
I have also tried giving the constraint using the wildcard_constraints member of the rule, and prefixed the string with an r or not.
Whatever I do, as soon as I uncomment the extract_dot rule, snakemake complains about the missing input file data/C.elegans/wtdbg2.3.dot in another rule. Note that there is a rule with output data/C.elegans/wtdbg2.3.dot.gz, and when changing this rule to output data/C.elegans/wtdbg2.3.dot instead, everything works as well.
So I conclude that the problem is in the regex. I have tested the regex on regex101.com, and it accepts wtdbg2.3.dot. But snakemake seems not to. Does anyone know if there is anything special about the snakemake regexes? Should they not be normal python regexes?
Does anyone know if there is anything special about the snakemake regexes? Should they not be normal python regexes?

No, nothing special.  The Snakemake documentation just links to the Python re module documentation.
I think this is something strange in how the anchors ^ and $ behave when matching wildcards, and not anything else in your particular regular expression.  Check out the pattern-matching with this dummy Snakefile:
rule all:
    input: [&quot;data/subdir/example&quot;, &quot;data/example&quot;, &quot;example&quot;]

rule anchored_example_of_subdir:
    &quot;&quot;&quot;Can't add either ^ or $ or this will fail&quot;&quot;&quot;
    output: &quot;data/{subdir,subdir}/example&quot;

rule anchored_example_in_subdir:
    &quot;&quot;&quot;Can't add ^ or this wil fail&quot;&quot;&quot;
    output: &quot;data/{file,example$}&quot;

rule anchored_example:
    &quot;&quot;&quot;This works with both ^ and $"""
output: "{file,^example$}&quot;

(There are no inputs or actions so it's just a matter of what filenames match what rules, and the regular expressions do nothing but match exact strings.)  This &quot;works&quot; as is (snakemake -nrp shows what you expect) but if you add in anchors as described in the docstrings above the upper two rules no longer match the expected filenames.  It's as if (and maybe is?) under the hood Snakemake is trying to apply the expression to the entire path.
Can you just drop your ^ and $?  The snakemake documentation implies that it's using the equivalent of re.match rather than re.search already, with wording like &quot;Here we could restrict the wildcard dataset to consist of digits only using \d+ as the corresponding regular expression&quot; so I don't think it's necessary anyway.

Edit: I think I found the issue in the snakemake source.  It munges your constraints together into one larger regular expression for the entire file path, so ^ and $ get embedded inside the resulting expression.  This looks like something that should at least be clarified in the documentation.