#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^\w++\W++((?<=\")[\w-]+(?="))\W+((?<=\")[\w-]+(?="))[\S\s]+?(count\W+=.*)[\S\s]+?^}$"
Local $sString = "resource "aws_iam_role" "my_test_payer_specific_role" {" & @CRLF & _
" count = "${(var.payer_account == "380834257621")?1:0}"" & @CRLF & _
"" & @CRLF & _
" name = "my_test_payer_specific_role"" & @CRLF & _
" max_session_duration = "7200"" & @CRLF & _
" assume_role_policy = "${data.aws_iam_policy_document.my_test_payer_specific_role-policy.json}"" & @CRLF & _
" tags = "${var.resources_tags}"" & @CRLF & _
" lifecycle {" & @CRLF & _
" ignore_changes = [" & @CRLF & _
" "permissions_boundary"" & @CRLF & _
" ]" & @CRLF & _
" }" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"resource "aws_iam_role_policy_attachment" "my_test_payer_specific_role-policy-attachment" {" & @CRLF & _
" role = "${aws_iam_role.my_test_payer_specific_role.name}"" & @CRLF & _
" count = "${(var.payer_account == "380834257621")?1:0}"" & @CRLF & _
" policy_arn = "arn:${var.partition}:iam::aws:policy/AdministratorAccess"" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"data "aws_iam_policy_document" "my_test_payer_specific_role-policy" {" & @CRLF & _
" count = "${(var.payer_account == "380834257621")?1:0}"" & @CRLF & _
" statement {" & @CRLF & _
" actions = ["sts:AssumeRole"]" & @CRLF & _
"" & @CRLF & _
" principals {" & @CRLF & _
" type = "AWS"" & @CRLF & _
" identifiers = ["arn:${var.partition}:iam::${var.payer_account}:root", "arn:${var.partition}:iam::380834257621:root"]" & @CRLF & _
" }" & @CRLF & _
" }" & @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