Try this:
(.+?)(\.[^.]*$|$)
This will:
- Capture filenames that start with a dot (e.g.
.logs
is a file named.logs
, not a file extension), which is common in Unix. - Gets everything but the last dot:
foo.bar.jpeg
gets youfoo.bar
. - Handles files with no dot:
secret-letter
gets yousecret-letter
.
Note: as commenter j_random_hacker suggested, this performs as advertised, but you might want to precede things with an anchor for readability purposes.