Direct approach:
To answer your question as it's written, this will provide the most exact match:
^\\\\my-local-server\\path\\to\\(.+)\.pdf$
General approach:
This regex is short and simple, matches any filename in any folder (with or without extension) on both windows and *NIX:
.*[\\/]([^.]+)
If a file has multiple dots in its name, the above regex will capture the filename up to the first dot. This can easily be modified to match until the last dot if you know that you will not have files without extensions or that you will not have a path with dots in it.
If you know that the folder will only contain .pdf files or you are only interested in .pdf files and also know that the extension will never be misspelled, I would use this regex:
.*[\\/](.+)\.pdf$
Explanation:
.
matches anything except line terminators.
*
repeats the previous match from zero to as many times as possible.
[\\/]
matches a the last backslash or forward slash (previous ones are consumed by .*
). It is possible to omit either the backslash or the forward slash if you know that only one type of environment will be used.
If you want to capture the path, surround .*
or .*[\\/]
in parenthesis.
- Parenthesis will capture what is matched inside them.
[^.]
matches anything that is not a literal dot.
+
repeats the previous match one or more times, as many as possible.
\.
matches a literal dot.
pdf
matches the string pdf.
$
asserts the end of the string.
If you want to match files with zero, one or multiple dots in their names placed in a variable path which also may contain dots, it will start to get ugly. I have not provided an answer for this scenario as I think it is unlikely.
Edit: To also capture filenames without a path, replace the first part with (?:.*[\\/])?
, which is an optional non-capturing group.