regex - C# Check if filename ends with pattern -
with list of file names below:
- foo.pdf
- foo(1).pdf
- foo(2).pdf
- foo(321).pdf
how can check if file name ends pattern (n).extension? , if does, how filename without (n) part?
this seems work
void main() { string test = "file(321).pdf"; string pattern = @"\([0-9]+\)\."; bool m = regex.ismatch(test, pattern); if(m == true) test = regex.replace(test, pattern, "."); console.writeline(test); }
Comments
Post a Comment