#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?x) \(\?P<(\w+)> # named group (name captured as group 1): (?P<name> " & @CRLF & _
" ( # matching pattern as group (2) in form: b(R1)a1...(R2)a2" & @CRLF & _
" [^)(]*+ # `b` (before) part - any not `)(` characters" & @CRLF & _
" (?: # non capturing group for repeated `(R)a` " & @CRLF & _
" \((?2)\) # `R` - reference to group 2 for possible nested braces " & @CRLF & _
" [^)(]*+ # 'a' (after) part - any not `)(` characters" & @CRLF & _
" )* # `(R)a` repetition is optional" & @CRLF & _
" ) # end the group 2 " & @CRLF & _
" \) # end of the named group to match"
Local $sString = "(?P<kind>(frames_cleanpass)|(disparity))/(?P<subset>\w+)/(?P<scene_1>\w+)/(?P<scene_2>\w+)/(?P<side>\w+)/(?P<scene_3>\w+)\.(?P<ext>(?(3)pfm|png))"
Local $sSubst = "{\1}"
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