#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?:-|role:)??\binfo-ansible(?=[\s,])"
Local $sString = "- { role: info-ansible, }" & @CRLF & _
"- { role: info-ansible" & @CRLF & _
"- info-ansible" & @CRLF & _
"" & @CRLF & _
"- info-ansibleasdasd" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"- info-ansible-" & @CRLF & _
"- info-ansibleasd" & @CRLF & _
"" & @CRLF & _
"- { role: info-ansible, db_type: "emg db", hosts_dns: "{{ env_db_emg_hosts_file_dns }}", activate_server_ip: "{{ shared_db_passive_emg_server_ip }}" }" & @CRLF & _
"- { role: loadbalancer-remove-node, pool_host_port: '{{ env_db_port }}', pool_host_name: "{{ common_db_active_emg_server }}", pool_name: '{{ env_loadbalancer_vservers.active_emg_db.pool.pool_name }}' }" & @CRLF & _
"" & @CRLF & _
",role: info-ansible" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm