I have started to study regex and used this as a practical problem. Here is a regex solution, it is not in a function but if you follow through my workings you probably could rebuild the regex for different directory patterns if required.
# valid file structure
$a="C:\sub0\sub1\sub2\sub3\sub7\xA12_ -x.sml"
$b="C:\sub0\sub2\sub1\sub3\sub7\yy.sml"
# simple file matches
$a -match ".*?\.sml"
$a -match "C:\\.*?\.sml"
# powershell regex is case insensitive by default so a-z matches uppercase too
$a -match "[a-z]:\\.*?\.sml"
# match specific directory structure
$a -match "[a-z]:\\.*?\\sub1\\.*?sub7\\.*?\.sml"
# use variables
$dir1="sub1"
$dir2="sub7"
$a -match "[a-z]:\\.*?\\($dir1)\\.*?($dir2)\\.*?\.sml"
# use variable for extension too
$ext="\.sml"
$a -match "[a-z]:\\.*?\\($dir1)\\.*?($dir2)\\.*?($ext)"
# tighten up the directory matching
$a -match "[a-z]:\\.*?($dir1).*?($dir2)\\.*?($ext)"
# tighten up the filename matching
$a -match "^[a-z]:\\.*?($dir1).*?($dir2)\\[a-z0-9-_\s]{0,256}($ext)$"
# final script
dir c:\ -r -ea 0| %{if($_.fullname -match "^[a-z]:\\.*?($dir1).*?($dir2)\\[a-z0-9-_\s]{0,256}($ext)$"){$_.fullname}}