Regex in starlark

Hi, I’m using .drone.star as my pipeline script:

Variables in my starlark file:

microservices_targets_regex = "^//services/(.*?)/cmd/senna-\\\\1:senna-\\\\1$"
impacted_targets_path = "/tmp/impacted_targets.txt"
filtered_targets_path = "/tmp/filtered_targets.txt"

Pipeline step (in my .drone.star file) which uses these variables:

'grep -E "{microservices_target_regex}" {impacted_targets_path} > {filtered_targets_path} || true'.format(
                        microservices_target_regex = microservices_targets_regex,
                        impacted_targets_path = impacted_targets_path,
                        filtered_targets_path = filtered_targets_path,
                    ),

generated step in yaml file:

grep -E "^//services/(.*?)/cmd/senna-:senna-$" /tmp/impacted_targets.txt > /tmp/filtered_targets.txt || true

But I expect to be:

grep -E "^//services/(.*?)/cmd/senna-\\1:senna-\\1$" /tmp/impacted_targets.txt > /tmp/filtered_targets.txt || true

I got a space char instead of \\1 in the result! do I’m doing something wrong?

Hello Mehran,

Kindly do a quick test and make the change to the starlark file and test the same with “\\s” instead of “\\1” if this gives the expected output.

Thanks @csgit but \\s does not give the expected output. I need to backreferences in my regex.