Regex based rules clause does not work

I want my Gitlab CI job to not run when the commit message starts with a particular string: [maven-scm]

So, I have the below configuration in my .gitlab-ci.yaml file:

image: maven:3.6.3-jdk-11-slim

stages:
  - test

test:
  stage: test
  cache:
    key: all
    paths:
      - ./.m2/repository
  script:
    - mvn clean checkstyle:check test spotbugs:check
  rules:
    - if: '$CI_COMMIT_MESSAGE !~ /^\[maven-scm\] .*$/'

My commit message is: [maven-scm] I hope the test job does not run

But the test job still runs to my frustration. I went over the GitLab documentation for rules but could not find the reason why the job still runs. I am not sure if I am missing something.

Would be great if someone can point me in the right direction.