#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?mx)\A # Begin at the beginning only! (No doing it again)" & @CRLF & _
" (?: # Non-capturing group consuming the string" & @CRLF & _
" (?| # Branch reset on two groups: p2 and p3 (p for prefix)" & @CRLF & _
" . # Consume a character" & @CRLF & _
" (?=.*+\n(?<p2>\k<p2>?+.) # Lookahead: Go to next line. Then add a character to a group" & @CRLF & _
" .*+\n(?<p3>\k<p3>?+.)) # Same. Will fail if the line is too short." & @CRLF & _
" | # When the first brach fails:" & @CRLF & _
" .*+\n(?<p2>)(?<p3>) # Consume the rest of the string. Reset the groups." & @CRLF & _
" )+? # As little as possible (Only one character at a time)" & @CRLF & _
" (?<=X)(?=.*\n\k<p2>(?<=X).*\n\k<p3>(?<=X)) # Check to see if there's a column of X's" & @CRLF & _
" (?=[\s\S]*(?<count>[\s\S](?(<count>)\k<count>))) # Add a character to a count group at the end." & @CRLF & _
" )+ # Keep doing it until all is consumed"
Local $sString = "XX" & @CRLF & _
"XX" & @CRLF & _
"XX" & @CRLF & _
"X" & @CRLF & _
"X" & @CRLF & _
"X"
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