#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "http(?:s)?\:\/\/boards\.(4chan|4channel)\.org\/([a-z]*)\/thread\/([0-9]*)(?:\#[0-9a-z]*)?"
Local $sString = "https://boards.4chan.org/mlp/thread/5" & @CRLF & _
"http://boards.4chan.org/b/thread/570277846" & @CRLF & _
"https://boards.4chan.org/mlp/thread/19865655#q19865655" & @CRLF & _
"https://boards.4chan.org/mlp/thread/19775771" & @CRLF & _
"https://boards.4chan.org/co/thread/65737750#q65737750" & @CRLF & _
"https://boards.4channel.org/a/thread/241489992"
Local $sSubst = "Thread $3 on $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