#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "<p>(\s*)(<a(.*)>)?(\s*)(https?:\/\/)?(w{3}\.)?(instagram\.com)\/(p\/)?(?<photoID>[A-Za-z0-9-_]{11})(\S*)(\s*)(<\/a>)?(\s*)?<\/p>"
Local $sString = "Best case" & @CRLF & _
"<p>https://www.instagram.com/p/B9XK4J3jVui/</p>" & @CRLF & _
"" & @CRLF & _
"Whitespace" & @CRLF & _
"<p>" & @CRLF & _
" https://www.instagram.com/p/B9XK4J3jVui/" & @CRLF & _
"</p>" & @CRLF & _
"" & @CRLF & _
"Protocol variations" & @CRLF & _
"<p>http://www.instagram.com/p/B9XK4J3jVui/</p>" & @CRLF & _
"<p>www.instagram.com/p/B9XK4J3jVui/</p>" & @CRLF & _
"<p>instagram.com/p/B9XK4J3jVui/</p>" & @CRLF & _
"" & @CRLF & _
"Trailing slash or not" & @CRLF & _
"<p>http://www.instagram.com/p/B9XK4J3jVui/</p>" & @CRLF & _
"<p>http://www.instagram.com/p/B9XK4J3jVui</p>" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"Linked" & @CRLF & _
"<p><a href="http://www.instagram.com/p/B9XK4J3jVui/">http://www.instagram.com/p/B9XK4J3jVui/</a></p>" & @CRLF & _
"<p>" & @CRLF & _
" <a href="http://www.instagram.com/p/B9XK4J3jVui/">" & @CRLF & _
" http://www.instagram.com/p/B9XK4J3jVui/" & @CRLF & _
" </a>" & @CRLF & _
"</p>" & @CRLF & _
"" & @CRLF & _
"Extraneous URL params" & @CRLF & _
"<p>https://www.instagram.com/p/B9XK4J3jVui?foo=bar</p>" & @CRLF & _
"<p>https://www.instagram.com/p/B9XK4J3jVui?foo=bar&baz=buzz</p>"
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