Repository: traefik/traefik (language: go)

Issue:
ReplacePathRegex - Allow Empty String for `replacement`
### Welcome!

- [X] Yes, I've searched similar issues on [GitHub](https://github.com/traefik/traefik/issues) and didn't find any.
- [X] Yes, I've searched similar issues on the [Traefik community forum](https://community.traefik.io) and didn't find any.

### What did you expect to see?

Currently using `v2.10.7`, would like to request passing in an empty string for the `replacement` entry for the [ReplacePathRegex](https://doc.traefik.io/traefik/middlewares/http/replacepathregex/) middleware.  At the moment, I see that it requires the `replacement` entry to [not be empty](https://github.com/traefik/traefik/blob/c1ef7429771104e79f2e87b236b21495cb5765f0/pkg/middlewares/replacepathregex/replace_path_regex.go#L55) (with it [trimmed first](https://github.com/traefik/traefik/blob/c1ef7429771104e79f2e87b236b21495cb5765f0/pkg/middlewares/replacepathregex/replace_path_regex.go#L39)).

Main use case for this request is to remove any trailing slashes from the path without having to redirect (EDIT: it is acceptable to only remove the first trailing-slash for us):
```yml
http:
  middlewares:
    remove-trailing-slash-from-path:
      replacepathregex:
        regex: "/$"
        replacement: ""
```

Some points around the request/confusion:
- In the current documentation for the middleware, the [field `replacement`](https://doc.traefik.io/traefik/middlewares/http/replacepathregex/#replacement) doesn't mention that it needs to be non-empty or non-white space
- When testing out the values in [Regex101](https://regex101.com/r/Px222C/1) and in [Go Playground](https://go.dev/play/p/_BhJmJcxUv8) (noted in the `Tips` section in the docs), the replacement works as intended (i.e., trailing slash removed)
- Looks like [`keepTrailingSlash` was deprecated some time ago](https://github.com/traefik/traefik/issues/4247) + haven't found any answers or solutions to support current use case in the [Community Boards](https://community.traefik.io/search?q=trailing%20slash)

Any Traefik-ers have suggestions around how to do this with the latest version of Traefik, it'll be greatly appreciated, would like this to be considered as a feature request, thanks!


Discussion / hints:

Fix patch:
diff --git a/pkg/middlewares/replacepathregex/replace_path_regex.go b/pkg/middlewares/replacepathregex/replace_path_regex.go
index fea6fa2dec..fb2c471891 100644
--- a/pkg/middlewares/replacepathregex/replace_path_regex.go
+++ b/pkg/middlewares/replacepathregex/replace_path_regex.go
@@ -53,7 +53,7 @@ func (rp *replacePathRegex) ServeHTTP(rw http.ResponseWriter, req *http.Request)
 		currentPath = req.URL.EscapedPath()
 	}
 
-	if rp.regexp != nil && len(rp.replacement) > 0 && rp.regexp.MatchString(currentPath) {
+	if rp.regexp != nil && rp.regexp.MatchString(currentPath) {
 		req.Header.Add(replacepath.ReplacedPathHeader, currentPath)
 		req.URL.RawPath = rp.regexp.ReplaceAllString(currentPath, rp.replacement)
 


Test patch:
diff --git a/pkg/middlewares/replacepathregex/replace_path_regex_test.go b/pkg/middlewares/replacepathregex/replace_path_regex_test.go
index 59018d7841..b7e6378519 100644
--- a/pkg/middlewares/replacepathregex/replace_path_regex_test.go
+++ b/pkg/middlewares/replacepathregex/replace_path_regex_test.go
@@ -44,6 +44,28 @@ func TestReplacePathRegex(t *testing.T) {
 			expectedRawPath: "/who-am-i/and/who-am-i",
 			expectedHeader:  "/whoami/and/whoami",
 		},
+		{
+			desc: "empty replacement",
+			path: "/whoami/and/whoami",
+			config: dynamic.ReplacePathRegex{
+				Replacement: "",
+				Regex:       `/whoami`,
+			},
+			expectedPath:    "/and",
+			expectedRawPath: "/and",
+			expectedHeader:  "/whoami/and/whoami",
+		},
+		{
+			desc: "empty trimmed replacement",
+			path: "/whoami/and/whoami",
+			config: dynamic.ReplacePathRegex{
+				Replacement: " ",
+				Regex:       `/whoami`,
+			},
+			expectedPath:    "/and",
+			expectedRawPath: "/and",
+			expectedHeader:  "/whoami/and/whoami",
+		},
 		{
 			desc: "no match",
 			path: "/whoami/and/whoami",