This is the first time that I heard about this feature. Extremely useful.
Looks like it was introduced in samtools version 1.12 (March 2021)
https://github.com/samtools/samtools/releases/
samtools view now works with the filtering expressions introduced by HTSlib. The filtering expression is passed to the program using the specific option -e or the global long option --input-fmt-option. E.g.
samtools view -e 'qname =~ "#49$" && mrefid != refid && refid != -1 && mrefid != -1' align.bam
for those with older versions of samtools:
mamba install samtools==1.12