#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)(.+> )?([^>]+)(.+)? > \2(.+)?"
Local $sString = " Boating > Anchoring > Accessories > Anchors/Chain/Rope" & @CRLF & _
" Boating > Safety > Fire & Vapor Detectors > Fume Detectors" & @CRLF & _
" Clothing > Sportswear > Shirts > T-Shirts Polo" & @CRLF & _
" Gear > Knives & Tools > Knives Fixed Blade > Fixed Blade Knives" & @CRLF & _
" Hunting > Tree Stands > Accessories > Tree Stands and Accessories" & @CRLF & _
" Optics > Rings & Mounts > Scope Rings > Rings & Accessories" & @CRLF & _
" Gear > Climbing & Rappelling > Rope Cord Webbing > Rope Cord & Webbing" & @CRLF & _
"" & @CRLF & _
" Fishing > Rod & Reel Combos > Rod & Reel Combos > Types of Fishing > Fishing Gear - Kids > Offshore Fishing Gear > Saltwater Fly Fishing Gear > Trolling Fishing Gear" & @CRLF & _
"" & @CRLF & _
" Fishing > Lures > Hard Baits > Lures Hard Baits" & @CRLF & _
""
Local $sSubst = "\1\2\3\4"
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