#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?ms)^(?<indent>\s*)(?<mod1>\w+)\s(?<mod2>\w+)?\s*(?<mod3>\w+)?\s*(?<return>\b\w+)\s(?<name>\w+)\((?<arg>.*?)\)\s*\{(?<body>.+?)^\k<indent>\}"
Local $sString = "public static FieldsConfig getFieldsConfig(){" & @CRLF & _
" if(xxx) {" & @CRLF & _
" sssss;" & @CRLF & _
" }" & @CRLF & _
" return;" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
" public String getAsSeparateGroup(String groupName) {" & @CRLF & _
" String begin = pattern.substring(0,getStart());" & @CRLF & _
" String mid = pattern.substring(getStart(),getEnd());" & @CRLF & _
" String finish = pattern.substring(getEnd());" & @CRLF & _
" return begin + "(?<" + groupName + ">" + mid + ")" + finish;" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" @Override" & @CRLF & _
" public static final String toString() {" & @CRLF & _
" return asString;" & @CRLF & _
" }" & @CRLF & _
"" & @CRLF & _
" public String directMatch(String match) {" & @CRLF & _
" Matcher matcher = Pattern.compile(getAsSeparateGroup("test")).matcher(match);" & @CRLF & _
" matcher.find();" & @CRLF & _
" String result;" & @CRLF & _
" try {" & @CRLF & _
" result = matcher.group("test");" & @CRLF & _
" }catch (Exception ex) {" & @CRLF & _
" result = "empty";" & @CRLF & _
" }" & @CRLF & _
" return getPattern() + ":" + result;" & @CRLF & _
" }" & @CRLF & _
"}"
Local $sSubst = ""
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