#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?sx)^((?!\bfruit\b).)* # nothing with "fruit" before" & @CRLF & _
"( # then, either:" & @CRLF & _
"# 1. fruit apple, followed by things that are not "fruit", followed by fruit banana, non-fruits, and then fruit cherry, or vice versa" & @CRLF & _
"\bfruit\b\ apple((?!\bfruit\b).)*(\bfruit\b\ banana((?!\bfruit\b).)*fruit\ cherry|fruit\ cherry((?!\bfruit\b).)*fruit\ banana)" & @CRLF & _
"|" & @CRLF & _
"# 2. Same with banana at the beginning" & @CRLF & _
"fruit\ banana((?!\\bfruit\b).)*(fruit\ apple((?!\bfruit\b).)*fruit\ cherry|fruit\ cherry((?!\bfruit\b).)*fruit\ apple)" & @CRLF & _
"|" & @CRLF & _
"# 3. And with cherry" & @CRLF & _
"fruit\ cherry((?!\bfruit\b).)*(fruit\ apple((?!\bfruit\b).)*fruit\ banana|fruit\ banana((?!\bfruit\b).)*fruit\ apple)" & @CRLF & _
")" & @CRLF & _
"((?!\bfruit\b).)*$ # no more fruit"
Local $sString = "fruit apple " & @CRLF & _
"some other config line" & @CRLF & _
"############" & @CRLF & _
"fruit banana" & @CRLF & _
"" & @CRLF & _
"fruit cherry" & @CRLF & _
"other config 1" & @CRLF & _
"" & @CRLF & _
"other config"
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