regex_search returns None when there is no match, and not an empty string
Summary
regex_search doc states "Return value (string) : Matched string or empty string if no match."
I discovered that it is not the case, and testing for == "" silently fails. Upon debugging, it turned out that when there is no match regex_search returns None. The documentation should be updated to reflect this.
Issue Type
Documentation Report
Component Name
lib/ansible/plugins/filter/core.py
Ansible Version
$ ansible --version
ansible [core 2.14.16]
config file = None
configured module search path = ['/home/zerodeux/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/zerodeux/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.2 (main, Sep 14 2024, 03:00:30) [GCC 12.2.0] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
Configuration
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
OS / Environment
Debian 12
Additional Information
Well, it fixes a wrong fact. Which led to some debug time which could be spared on lots of Ansible users. That's an improvement.
Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
Files identified in the description:
If these files are incorrect, please update the component name section of the description or use the component bot command.
This topic is covered by https://docs.ansible.com/ansible-core/devel/reference_appendices/faq.html#why-does-the-regex-search-filter-return-none-instead-of-an-empty-string
As well as the note in https://docs.ansible.com/ansible-core/devel/playbook_guide/playbooks_filters.html#searching-strings-with-regular-expressions
So maybe mention those links in https://docs.ansible.com/ansible/latest/collections/ansible/builtin/regex_search_filter.html ?
will update filter docs to reflect this info