Use wildcard regex in Include:rules:if statement

I am trying to find the best way to use a wildcard regex statement when using an include:rules:if statement, but I have tried dozens of versions without luck, and I have searched endlessly on this topic, but either the documentation referenced is no longer there, or the examples aren’t sufficient.

This example works when I explicitly name the file:

include: 
  - local: my.gitlab-ci.yml
    rules:
      - if: $CI_COMMIT_BRANCH == "test_lst_r1"

But I need something like this to work:

include: 
  - local: my.gitlab-ci.yml
    rules:
      - if: $CI_COMMIT_BRANCH == "*_lst_r1"

I’ve tried multiple variations on this, but without luck:

=~ /^_lst_r1/
=~ /^((?!_lst_r1).)*$/
=~ /^.*$_lst_r1/

etc

Appreciate any help/insight into getting this to work.
Thanks

this works:

  - local: my.gitlab-ci.yml
    rules:
      - if: $CI_COMMIT_BRANCH =~ /.*_lst_r1/

Either you don’t need the wildcard or you need an anchor here. In your example your pattern would match all of these:

hello_lst_r1
_lst_r1234
hello_lst_r1234

Without anchors like ^ and $ (start of string, end of string), regex will default to searching for the pattern anywhere in the string. So if your goal is to just match any of these strings, then this works fine: _lst_r1, no wildcards needed. If you only want to only match strings like this, then what you actually need is an anchor, not a wildcard:

hello_lst_r1
goodbye_lst_r1

You’d use a pattern like this: /_lst_r1$/, and it would prevent matching strings like this:

hello_lst_r12
hello_lst_r13