I've got a file with a unique substring in the file name. Therefore I'm matching it with a regex. For example, lets say that the file name is someFile.asdf1234.txt.
$fileNameRegex = [regex] 'someFile\.(.*).txt'
$fileName = Get-ChildItem C:\test | Where-Object {$_.Name -Match $fileNameRegex}
# $fileName = 'someFile.asdf1234.txt'
# so far this works.
What I'm having a hard time doing is use this info to rename the file
$arbitraryString = "random9753"
# the final file name needs to be "someFile.random9753.txt"
How do I reuse the same regex to rename the substring portion of the file name with the new $arbitrartyString?
note: I don't mind changing the regex to meet the needs (possibly using groups), but I need to only have a single regex.