For this example string 4711_001.doc, using [^_.]*
and \.[^.]+
is quite a broad match as it can match any character except what is listed in the character class.
Perhaps you could make the pattern a bit more specific, matching digits at the start and word characters as the extension.
In the replacement use capture group 1 and 2, often denoted as $1$2
or \1\2
(\d+)_\d+(\.\w+)
Regex demo
There is no language tagged, but if for example \K
is supported to clear the match buffer this might also be an option (including the parts that you tried)
In the replacement use an empty string.
[^_.]*\K_[^._]+(?=\.[^.]+$)
In parts
[^_.]*\K
Match the part before the underscore, then forget what is matched so far
_[^._]+
Match the underscore, follwed by 1+ chars other than .
and _
(?=\.[^.]+$)
A positive lookahead assertion to make sure what is at the right is a .
followed by any char other than a .
until the end of the string.
Regex demo