#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^[^\W\d_]+\.?(?:[- ][^\W\d_]+\.?)*$"
Local $sString = "Valid street names are:" & @CRLF & _
"Mainstreet." & @CRLF & _
"Mainstreet" & @CRLF & _
"Main Street" & @CRLF & _
"Big New mainstreet" & @CRLF & _
"Mainstreet-New" & @CRLF & _
"Mains Str." & @CRLF & _
"St. Alexander Street" & @CRLF & _
"abcÜüßäÄöÖàâäèéêëîï ôœùûüÿçÀÂ-ÄÈÉÊËÎÏÔŒÙÛÜŸÇ." & @CRLF & _
"John Kennedy Street" & @CRLF & _
"" & @CRLF & _
"Not valid street names are:" & @CRLF & _
"Mainstreet #+;:_*´`?=)(/&%$§!" & @CRLF & _
"Mainstreet#+;:_*´`?=)(/&%$§!" & @CRLF & _
"Mainstreet 2" & @CRLF & _
"Mainstreet.." & @CRLF & _
"Mainstreet§" & @CRLF & _
"" & @CRLF & _
"Valid cities are:" & @CRLF & _
"Edinôœùûüÿ" & @CRLF & _
"Berlin." & @CRLF & _
"St. Petersburg" & @CRLF & _
"New-Berlin" & @CRLF & _
"Aue-Bad Schlema" & @CRLF & _
"Frankfurt am Main" & @CRLF & _
"Nürnberg" & @CRLF & _
"Ab" & @CRLF & _
"New York CityßäÄöÖàâäèéêëîïôœùûüÿçÀÂ-ÄÈÉÊËÎÏÔŒÙÛÜŸ" & @CRLF & _
"Not valid cities are:" & @CRLF & _
"" & @CRLF & _
"Edingburgh 123" & @CRLF & _
"Edingburg123" & @CRLF & _
"St. Andrews 12" & @CRLF & _
"Berlin,#+;:_*´`?=)(/&%$§!" & @CRLF & _
"Berlin__" & @CRLF & _
"The solutions that I have at the moment matches very close but not perfectly:" & @CRLF & _
"" & @CRLF & _
"For city and street name:" & @CRLF & _
"Unfortunately no match for these examples (the rest works fine):" & @CRLF & _
"" & @CRLF & _
"St. Alexander Street" & @CRLF & _
"St. Petersburg" & @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