5

I have some variable with name 'MyVariable' and want to compare it with some string constant inside rules: if section inside job:

rules:
        - if: $MyVariable == 'some string'

But MyVariable actually can be in different cases, like:

SOME STRING
Some String
SoME strinG

and so on. Current comparison (==) is case-sensitive, and expression results to 'false' when MyVariable is not exactly 'some string' (in lower case). Is there any possibility compare two strings in case-insensitive way?

Tadeusz
  • 6,453
  • 9
  • 40
  • 58
  • Using `=~` lets you use a regular expression. You can use case-insensitive expression -- `- if: '$MyVariable =~ /(?i)some string/'` – sytech Nov 10 '21 at 11:39

1 Answers1

7

Using =~ instead of == lets you use a regular expression. You can use case-insensitive expression or add the case-insensitive flag i:

Regular expression flags must be appended after the closing /. Pattern matching is case-sensitive by default. Use the i flag modifier, like /pattern/i to make a pattern case-insensitive:

- if: '$MyVariable =~ /some string/i'

Additional references:

Regex: ignore case sensitivity

sytech
  • 29,298
  • 3
  • 45
  • 86