I have a weird problem with Regex.Replace.
I think my immediate window says it all:
pattern
"([^_]*)(.*)"
fileNameToReplicate
"{Productnr}_LEI1.JPG"
Regex.Replace(fileNameToReplicate, pattern, $"$1")
"{Productnr}"
Regex.Replace(fileNameToReplicate, pattern, $"$2")
"_LEI1.JPG"
Regex.Replace(fileNameToReplicate, pattern, $"sometext$2")
"sometext_LEI1.JPGsometext"
Thus, my pattern looks for the first underscore and captures everything until that underscore in group1.
Then it captures the rest of the text (starting with that underscore until the end of the string) and captures that as group 2.
The regex captures correctly, look here to review it.
Why is the prefixed text outputted twice? Once before the group, and once after the group. Obviously I expected to have this is output:
"sometext_LEI1.JPG"