The backslash must be escaped too (\\). For example,

    - debug:
        msg: OK
      loop: [' ', "'", '\', '"', '!', '}']
        
      when: item is match(context_regex)
      vars:
        context_regex: '^[a-zA-Z0-9-+.#$%&~*/=?^_ ''\\"!]$'

gives

    ok: [localhost] => (item= ) => {
        "msg": "OK"
    }
    ok: [localhost] => (item=') => {
        "msg": "OK"
    }
    ok: [localhost] => (item=\) => {
        "msg": "OK"
    }
    ok: [localhost] => (item=") => {
        "msg": "OK"
    }
    ok: [localhost] => (item=!) => {
        "msg": "OK"
    }
    skipping: [localhost] => (item=})


HTH,

        -vlado

-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200604094602.678af4a0%40gmail.com.

Attachment: pgpNwYdZ0Zjbu.pgp
Description: OpenPGP digital signature

Reply via email to