Regex redirect challenge

While attempting to create a regex redirect I continue to run into an error condition. The regex is valid outside of the Docker/Traefik YAML file. However, always returns an error related to the '.' character.

The complete middleware clause is as follows:
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^(?:www.)?(.+)

If I double the backslashes the issue disappears, but the results suffer.

Any assistance would be appreciated.

You do not have closing quotation mark in your expression. You also do not have any backslashes in it single or double.

How do you know that the regex is valid outside of the Docker/Traefik YAML file? What error are you getting? How the results suffer?

First thank you for your response.

The missing quote was a typo when copying the string into forum.

As for the missing backslash, it appears to be an issue with the forum. If I return to edit my original post the backslash is there between the www and the '.'.

I used regex101 to validate my expressions. Here is the decode provided:
`

^(?:www.)?(.+)

`

^ asserts position at start of the string

Non-capturing group

(?:www.)?

? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)

www matches the characters www literally (case sensitive)

. matches the character . literally (case sensitive)

1st Capturing Group

(.+)

.+

matches any character (except for line terminators)

  • Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)

Regards

try using code block either single or triple `
Triple ` example

# eg 
^(?:www\.)
# or  using ` in your code example
label.rule = Host(`foo.bar.com`)