Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Need to write a Regex in docker-compose environment variable

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading