From 1ca03139ccf46745015fb0d4ce78ed00cf8d9115 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 11 Jul 2023 19:38:36 -0700 Subject: [PATCH] Update regex_* docs (#81016) * Update regex_* docs * Remove Python 3 regex link * Added references to inline regex flags Signed-off-by: Abhijeet Kasurde --- lib/ansible/plugins/filter/regex_findall.yml | 6 ++++++ lib/ansible/plugins/filter/regex_replace.yml | 6 ++++++ lib/ansible/plugins/filter/regex_search.yml | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/lib/ansible/plugins/filter/regex_findall.yml b/lib/ansible/plugins/filter/regex_findall.yml index 0a66ca0a01d..7aed66cc05c 100644 --- a/lib/ansible/plugins/filter/regex_findall.yml +++ b/lib/ansible/plugins/filter/regex_findall.yml @@ -27,6 +27,12 @@ EXAMPLES: | # all_pirates => ['CAR', 'tar', 'bar'] all_pirates: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_findall('^.ar$', multiline=True, ignorecase=True) }}" + # Using inline regex flags instead of passing options to filter + # See https://docs.python.org/3/library/re.html for more information + # on inline regex flags + # all_pirates => ['CAR', 'tar', 'bar'] + all_pirates: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_findall('(?im)^.ar$') }}" + # get_ips => ['8.8.8.8', '8.8.4.4'] get_ips: "{{ 'Some DNS servers are 8.8.8.8 and 8.8.4.4' | regex_findall('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}" diff --git a/lib/ansible/plugins/filter/regex_replace.yml b/lib/ansible/plugins/filter/regex_replace.yml index 72c26f54995..ced9395deae 100644 --- a/lib/ansible/plugins/filter/regex_replace.yml +++ b/lib/ansible/plugins/filter/regex_replace.yml @@ -40,6 +40,12 @@ EXAMPLES: | # piratecomment => '#CAR\n#tar\nfoo\n#bar\n' piratecomment: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_replace('^(.ar)$', '#\\1', multiline=True, ignorecase=True) }}" + # Using inline regex flags instead of passing options to filter + # See https://docs.python.org/3/library/re.html for more information + # on inline regex flags + # piratecomment => '#CAR\n#tar\nfoo\n#bar\n' + piratecomment: "{{ 'CAR\ntar\nfoo\nbar\n' | regex_replace('(?im)^(.ar)$', '#\\1') }}" + RETURN: _value: description: String with substitution (or original if no match). diff --git a/lib/ansible/plugins/filter/regex_search.yml b/lib/ansible/plugins/filter/regex_search.yml index e2fbdb4b8f2..970de621954 100644 --- a/lib/ansible/plugins/filter/regex_search.yml +++ b/lib/ansible/plugins/filter/regex_search.yml @@ -29,6 +29,12 @@ EXAMPLES: | # db => 'database42' db: "{{ 'server1/database42' | regex_search('database[0-9]+') }}" + # Using inline regex flags instead of passing options to filter + # See https://docs.python.org/3/library/re.html for more information + # on inline regex flags + # server => 'sErver1' + db: "{{ 'sErver1/database42' | regex_search('(?i)server([0-9]+)') }}" + # drinkat => 'BAR' drinkat: "{{ 'foo\nBAR' | regex_search('^bar', multiline=True, ignorecase=True) }}"