Check if string contains "Text"+"Numbers" (Regex)


I want to rename files in a folder that contains the following pattern:

“TargetString”+“RandomSequenceOfNumber”, for example,“TargetString166120.pdf” should become “166120.pdf” and “TargetString99999.pdf” should become “99999.pdf”

However, in the same folder, I have files of the type “TargetString” that shouldnt be renamed.

Can anyone help me?

If MyFile is the original filename:
System.Text.RegularExpressions.Regex.Replace(MyFile, "^TargetString", String.Empty).

This only replaces text “TargetString” at the beginning of the filename and nowhere else.

1 Like


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.