I’m trying to write this environment variable:
ExpectedRegex=^[\\"rn ]*A\$$$$
(Meaning: allow [, ", r, n, (space)] for any number of times, then require "A$". Matching the start and end of the string)
docker-compose.yml snap:
environment:
- ExpectedRegex=^[\\"rn ]*A\$$$$
But docker-compose returns me this regex:
REGEX=^[\\\"rn ]*A\\$$
The problem lies in the last dollar which docker-compose adds another \ before it.
Inside the container I’m using .Net Core to match the regex. When debug-printing the string received I see the double backslash
How can I write the regex in the docker-compose yaml file so that it doesn’t get double backslashed?
>Solution :
I assume, regex is in environment variables, yes?
You can use single quotes to escape it. Something like this:
version: '3.7'
services:
something:
image: something:latest
environment:
REGEX: '^[\\"rn ]*A\$$$$'
// more parameters below
also i think last 4 $ signs are wrong here, seems like only first not escaped is took into account, i think you need to escape all of them, but the last one:
REGEX: '^[\\"rn ]*A\$\$\$$'
Last one to match end of string, i mean.