Conditional wild card usage

Is there any way I can use the wild cards or regex in when statements,

when: ansible_distribution_major_version|int == 6 or ansible_fqdn == “test[0-1][0-9].example.com”

I actually do not want to pass hostname of my server in vars section. Will this regex work with in conjunction with Ansible facts ?

During my playbook execution time, it need to interpret my hostname of the server from fact ansible_fqdn.

Samole playbook,

hosts: localhost
tasks:
name: debug
debug:
msg: “passed”
when: “ansible_distribution_major_version|int == 6 or ansible_fqdn | regex_search(‘test[0-9][0-1]-[0-9][0-9].example.com’)”

See "Testing strings"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#testing-strings

For example

  - hosts: localhost
    vars:
      hostnames:
        - test56.example.com
        - testXY.example.com
      my_regex: '^test(\d\d)\.example\.com'
    tasks:
      - debug:
          msg: OK
        loop: "{{ hostnames }}"
        when:
          item is match(my_regex)

gives

  ok: [localhost] => (item=test56.example.com) =>
    msg: OK
  skipping: [localhost] => (item=testXY.example.com)