import re


def _valid_name(filename: str) -> bool:
    """Check for valid filename.

    - SampleName can contain letters, number or special characters (including _)
    - The number following S runs from 1 to 99
    - The number following L runs from 001 to 999
    - R1 stands for file 1 and R2 for file 2 of a pair (no other numbers are allowed)
    - The last number block runs from 001 to 999
    - The file name extension should end in fastq.gz (no extra extensions such as fastq.gz.md5)
    """
    pat = re.compile(
        r"\S+_S([1-9]|\d)_L\d\d[1-9]_R(1|2)_\d\d[1-9].fastq.gz", flags=re.IGNORECASE
    )
    return bool(pat.fullmatch(filename))