ok, here it is..... should be \\1 vs \1 in your replacement and test(is) on string contents(in)
msg: "{{ item }} is in the s"
loop: "{{ t_list }}"
when: ( item | regex_replace("^p(\d+).*$", "\\1") ) is in s
- name: task 3.orig
debug:
msg: "{{ item }} is in s"
loop: "{{ t_list }}"
when: ( item | regex_replace("^p(\d+).*$", "\1") ) in s
TASK [task 3] ****************************************************************************************************
ok: [localhost] => (item=p1_xyz) => {
"msg": "p1_xyz is in the s"
}
ok: [localhost] => (item=p2_xyz) => {
"msg": "p2_xyz is in the s"
}
TASK [task 3.orig] ***********************************************************************************************
skipping: [localhost] => (item=p1_xyz)
skipping: [localhost] => (item=p2_xyz)
skipping: [localhost]
PLAY RECAP *******************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
I did this in a hurry, so there may be mistakes or more awesome ways of doing this. YMMV