how to fetch substring from vairbale or ansible vriable or facts

Hello Team,

How can we check if variable demo01 has 01 in it in ansible. i have server with hostanme server01 and server02 i want some task to be applied to only 01 machines how can i do it.

https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html