#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?s)^(.*?)\*\*\*\*\*\*\*"
Local $sString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus accumsan risus id ex dapibus sodales. " & @CRLF & _
"" & @CRLF & _
"Curabitur dui lacus, tincidunt vel ligula quis, volutpat mattis eros. " & @CRLF & _
"" & @CRLF & _
"In quis metus at ex auctor lobortis. Aliquam sed nisi purus. Sed cursus odio erat, ut tristique sapien interdum interdum. Morbi vel sollicitudin ante, non pellentesque libero. " & @CRLF & _
"" & @CRLF & _
"***********" & @CRLF & _
"" & @CRLF & _
"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean egestas urna facilisis massa posuere, quis accumsan erat ornare. " & @CRLF & _
"" & @CRLF & _
"Curabitur at dapibus nibh. Nam nec vestibulum ligula. Phasellus bibendum mi urna, ac hendrerit libero interdum non. Suspendisse semper non elit aliquam auctor. " & @CRLF & _
"" & @CRLF & _
"Morbi vel sem tortor. Donec a sapien quis erat condimentum consequat in ut sem. Quisque in tellus sed est lobortis ultricies sed vitae enim." & @CRLF & _
"I want to return this value in B1:" & @CRLF & _
"" & @CRLF & _
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus accumsan risus id ex dapibus sodales. " & @CRLF & _
"" & @CRLF & _
"Curabitur dui lacus, tincidunt vel ligula quis, volutpat mattis eros. " & @CRLF & _
"" & @CRLF & _
"In quis metus at ex auctor lobortis. Aliquam sed nisi purus. Sed cursus odio erat, ut tristique sapien interdum interdum. Morbi vel sollicitudin ante, non pellentesque libero. " & @CRLF & _
"Which is basically anything before the pattern *******. In Python, I can add the re.DOTALL to the .* but I can't get this to work in Google Sheets." & @CRLF & _
"" & @CRLF & _
"regexgoogle-spreadsheet" & @CRLF & _
"shareeditcloseflag" & @CRLF & _
"asked 3 hours ago" & @CRLF & _
"" & @CRLF & _
"aylim14" & @CRLF & _
"83" & @CRLF & _
"Try using stackoverflow.com/a/159140/5267751. – user202729 3 hours ago" & @CRLF & _
"Thanks! I did. But it didn't work. That was one of the first thing I tried. It kept returning everything and didn't stop at the *. The suggestion gave by Poul looks like it worked. But I can't say for sure until new data gets added to the spreadsheet. – aylim14 1 hour ago " & @CRLF & _
"add a comment" & @CRLF & _
"2 Answers" & @CRLF & _
"active oldest votes" & @CRLF & _
"up vote" & @CRLF & _
"0" & @CRLF & _
"down vote" & @CRLF & _
"This simple RegEx should do the trick (although I don't know anything about Google-spreadsheets):" & @CRLF & _
"" & @CRLF & _
"[^*]*(?=\*{11})" & @CRLF & _
"The first match should be what you want. It simply matches anything up the the first '*', making sure it's followed by 11 stars." & @CRLF & _
"" & @CRLF & _
"shareeditflag" & @CRLF & _
"edited 3 hours ago" & @CRLF & _
"answered 3 hours ago" & @CRLF & _
"" & @CRLF & _
"Poul Bak" & @CRLF & _
"1,680519" & @CRLF & _
"The *{11} actually doesn't matter. Sometimes, the separator is *****. Sometimes it's *\n*\n*\n* So I really just need it to stop at the first *. – aylim14 1 hour ago " & @CRLF & _
"I just substituted the [^*]* and I think it worked! Thanks so much. The spreadsheet gets updated once or twice a day.I'll monitor this to see if it works on new data. – aylim14 1 hour ago" & @CRLF & _
"add a comment" & @CRLF & _
"up vote" & @CRLF & _
"0" & @CRLF & _
"down vote" & @CRLF & _
"To make a dot match line breaks, you need to add (?s) to the pattern. To match any char, you may use a .. To match up to the leftmost occurrence, use lazy quantifier, *?. To actually extract a substring you need, wrap the part of the pattern you are interested in getting with capturing parentheses." & @CRLF & _
"" & @CRLF & _
"So, to match up to the first ******* substring, you may use" & @CRLF & _
"" & @CRLF & _
"(?s)^(.*?)\*\*\*\*\*\*\*" & @CRLF & _
"or (?s)^(.*?)\*{7}." & @CRLF & _
"" & @CRLF & _
"(?s) - a DOTALL modifier" & @CRLF & _
"^ - start of string" & @CRLF & _
"(.*?) - Group 1: any 0+ chars as few as possible" & @CRLF & _
"\*\*\*\*\*\*\* - 7 literal asterisk symbols." & @CRLF & _
"Note you cannot rely on a negated character class (that matches line breaks) if your substring may contain * chars, that is, ^([^*]*)\*\*\*\*\*\*\* won't work in those cases." & @CRLF & _
"" & @CRLF & _
"If you just want to match any chars up to the first * in the string, your regex will simplify greatly to" & @CRLF & _
"" & @CRLF & _
"^([^*]+)" & @CRLF & _
"It matches" & @CRLF & _
"" & @CRLF & _
"^ - start of string" & @CRLF & _
"([^*]+) - Capturing group 1: one or more chars other than *." & @CRLF & _
"shareeditdeleteflag" & @CRLF & _
"answered just now" & @CRLF & _
"" & @CRLF & _
"Wiktor Stribiżew" & @CRLF & _
"284k16113183" & @CRLF & _
"add a comment" & @CRLF & _
"Not the answer you're looking for? Browse other questions tagged regex google-spreadsheet or ask your own question." & @CRLF & _
"asked" & @CRLF & _
"" & @CRLF & _
"today" & @CRLF & _
"" & @CRLF & _
"viewed" & @CRLF & _
"" & @CRLF & _
"15 times" & @CRLF & _
"" & @CRLF & _
"active" & @CRLF & _
"" & @CRLF & _
"today" & @CRLF & _
"" & @CRLF & _
"BLOG" & @CRLF & _
"Developer Salaries in 2018: Updating the Stack Overflow Salary Calculator" & @CRLF & _
"HOT META POSTS" & @CRLF & _
"33 Generic “Don't Do It” Answer" & @CRLF & _
"30 What effect do voting rings have on average post quality?" & @CRLF & _
"58 C tag usage, radical changes to tag wiki. Which policy to keep?" & @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