#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)(?>\G(?!^)|^(?:.*?[^\p{P}\h\d\n])?[\p{P}\h]*+1?(?=(?1){10}(?!(?1))))((\d)[\p{P}\h]*+)(?:[^\d\n].*)?"
Local $sString = " +18005551212" & @CRLF & _
" 8005551213" & @CRLF & _
" 18005551214" & @CRLF & _
" (800)555-1215" & @CRLF & _
" 800.555.1216" & @CRLF & _
" (800) 555-1217" & @CRLF & _
" 800 555 12 18" & @CRLF & _
" " & @CRLF & _
" stuff before +18005551221 stuff after" & @CRLF & _
" stuff before 8005551222 stuff after" & @CRLF & _
" stuff before 18005551223 stuff after" & @CRLF & _
" stuff before (800)555-1224 stuff after" & @CRLF & _
" stuff before 800.555.1225 stuff after" & @CRLF & _
" stuff before (800) 555-1226 stuff after" & @CRLF & _
" stuff before 800 555 12 27 stuff after" & @CRLF & _
" " & @CRLF & _
" 5551212"
Local $sSubst = "$2"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
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