#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)(^|[^a-z])\((\d*|[a-z])\)"
Local $sString = "(x+2)/(x) -> only select ( ) in (x) " & @CRLF & _
"-(2)+. -> only select ( ) in (2)" & @CRLF & _
"(wsd). -> select nothing" & @CRLF & _
"(x)^2+2 -> only select ( ) in (x)" & @CRLF & _
"sin(x). -> select nothing" & @CRLF & _
"(22313)a. -> only select ( ) in (22313)" & @CRLF & _
"+23-3()/(3x)+(x). -> only select () in () and ( ) in (x)" & @CRLF & _
"sin(x)+3*x^2+(x)+23 -> only select ( ) in (x)"
Local $sSubst = "$1$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