#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}(?!([^<]*>)|(((?!<a).)*<\/a>))"
Local $sString = "<div id="departments">" & @CRLF & _
" <ul>" & @CRLF & _
" <li>Department 1 - 8141113900</li>" & @CRLF & _
" <li>Department 2 - pavan 8141119300</li>" & @CRLF & _
" <li>Department 3 - (555) 123-6789</li>" & @CRLF & _
" </ul>" & @CRLF & _
"</div>" & @CRLF & _
"<input type='text' value='(555) 123-6789' />" & @CRLF & _
"(555) 123-6789 <a href=''>(555) 123-6789</a><a href='(555) 123-6789'>(555) 123-6789</a>" & @CRLF & _
"<li>Department 1 -<b> (555) 123-1234</b></li>" & @CRLF & _
"<li>Department 2 - (555) 123-4321</li>" & @CRLF & _
"<li>Department 3 - (555) 123-6789</li>"
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