searching multi lines using regex

How to search multiple lines using regex in Ansible?

I tried below pattern and it is not working

regex: ^line con.(?:\n^\s.)

line console 0
password

I don’t think you can use caret " ^ " in the middle of a regex. It is probably trying to match a literal ^ symbol and not finding it. Try removing the caret.

Hi Bob,

here my code I removed ‘^’ still not working

  • set_fact:
    console: “{{ current_show_run[0] | map(‘regex_search’, qry, multiline=True | select(‘string’) | list }}”
    vars:
    qry: ‘^line con.*\n\spassword’

This list is for discussions about Ansible development. The Ansible
Project mailing list would be the right forum for your question. See
https://docs.ansible.com/ansible/latest/community/communication.html
for details.

The approach you are using works as expected in this test (caret included):

$ ansible localhost -m debug -a msg="{{ lines|map('regex_search',
'^line con.*\n^\s(.*)', multiline=True)|select('string')|list }}" -e
'{"lines":["foo\nbar","line console 0\n password","mine console
1\npassword","line console 2\nnospaceword","line console 3\n
otherpassword"]}'
localhost | SUCCESS => {
   "msg": [
       "line console 0\n password",
       "line console 3\n otherpassword"
   ]
}

Either the input data you're feeding it isn't what you expect, or your
pattern doesn't match the correct input.

-- Abhijit