;Spintax Test #include ; Text in Spintax format ;~ Global $a = 1 $spintext = '{{Hello|Hi|Howdy} {World|People|Dude}!}|{{Good Day|Excuse Me|Greetings} {Everyone|Ladys and Gents|Mister},} {AutoIt|C++|C|Java} is a{n {awesome|amazing}}|{{ wonderful|n astonishing}} {language|programming language}.' ConsoleWrite(Spintax($spintext) & @CRLF) ConsoleWrite(Spintax($spintext) & @CRLF) ConsoleWrite(Spintax($spintext) & @CRLF) ConsoleWrite(Spintax($spintext) & @CRLF) Func Spintax($sInput) ;~ ConsoleWrite("- Iteration "&$a&" Start -" & @CRLF) $SpinArray = StringRegExp($sInput, '{([^{]*?|[^{]*?)}',3); Global matches ;~ _ArrayDisplay($SpinArray,"") $sfinrep = StringReplace($sInput,"}|{","|") ; look For final replacing If Not IsArray($SpinArray) Then ;~ ConsoleWrite("!No Array!" & @CRLF) If $sfinrep = $sInput then ; Nothing replaced, so free of }|{ --> end string ;~ ConsoleWrite("+EndResult: " & @CRLF) Return $sInput EndIf ;else replace workstring with the string without }|{ for further processing $sInput = $sfinrep $SpinArray = StringRegExp($sInput, '{([^{]*?|[^{]*?)}',3); Global matches ;~ ConsoleWrite("final replaced string:" & @CRLF) ;~ ConsoleWrite($sInput & @CRLF) EndIf $TrimmedText = StringRegExpReplace($sInput, '{([^{]*?|[^{]*?)}',chr(0x1A)); or any other special char to mark where to insert $RNDText = $TrimmedText For $i = 0 To UBound($SpinArray)-1 $WordArray = StringSplit($SpinArray[$i], "|",3) $rnum = Random(0, UBound($WordArray)-1, 1); get random Array index $RNDText = StringReplace($RNDText, chr(0x1A), $WordArray[$rnum],1); replace only the next occurrence Next ;~ ConsoleWrite($RNDText & @CRLF) ;~ ConsoleWrite("- Iteration "&$a&" End -" & @CRLF) ;~ $a += 1 Return Spintax($RNDText) EndFunc