#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^(?P<content>(?:[-/][a-zA-Z0-9\-_]+)?=?)(?P<prefix>bazel-out|external)/"
Local $sString = "-Ibazel-out/k8-fastbuild/include" → Matches bazel-out/" & @CRLF & _
"-Lexternal/foo/lib" → Matches external/" & @CRLF & _
"--gcc-toolchain=bazel-out/toolchain" → Matches bazel-out/" & @CRLF & _
"-fmodule-output=external/module.pcm" → Matches external/" & @CRLF & _
"/Ibazel-out/k8-fastbuild/include" (MSVC, Windows) → Matches bazel-out\" & @CRLF & _
"--extract-api-ignores=external/bar,baz" → Matches external/" & @CRLF & _
"bazel-out/k8-fastbuild/source.c" (file field) → Matches bazel-out/" & @CRLF & _
"" & @CRLF & _
"Should Not Match" & @CRLF & _
"" & @CRLF & _
"-Ifoo/bazel-out/bar" (nested path) → No match" & @CRLF & _
"-Dmacro=bazel-out_value" (not a path) → No match" & @CRLF & _
"bazel-output/include" (similar name) → No match" & @CRLF & _
"-I externals/foo" (similar name) → No match" & @CRLF & _
"-I bazel-out/..." (space after -I) → No match (separate flags)"
Local $sSubst = "\g<content>dynamically-matched-new-prefix/"
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