#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?u)\bwith\s+(?!\P{P}*\bwith\b)(\P{P}+)"
Local $sString = "This is a test with a string with punctuation, and an end. Then test words, and more text. And here whith more text with more punctuation, like that." & @CRLF & _
"" & @CRLF & _
"It should also work with a sentence finishing by a dot." & @CRLF & _
"" & @CRLF & _
"And what do we do with fruits? such as apples, pears and lemons?" & @CRLF & _
"" & @CRLF & _
"Please come with this stuff:" & @CRLF & _
"- your laptop." & @CRLF & _
"- a block of paper." & @CRLF & _
"- a pencil." & @CRLF & _
"" & @CRLF & _
"I would not recommend sun bathing with just some oil!" & @CRLF & _
"" & @CRLF & _
"I don't think you want to match "with" if it's in a string."
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