AS3 RegExp find and replace paths by file type (file extension) on XML

[EN] I’ve run into an issue where I need to replace certain file paths from a XML file, the big problem is I don’t have control over the XML structure, so I need to replace the paths dynamically from AS3.
Thus, I want to share the solution I’ve made:

[ES] Me encuentro con el problema de que necesito reemplazar ciertas rutas de archivos desde un XML, el problema es que no controlo la estructura del XML, asi que necesito reemplazar las rutas de forma dinamica desde AS3.
Asi que aca comparto la solucion que construi:

================

/*
This will search for any file of type "_extensions" into "_sourceXML" and add the "_basepath" at the beginning:
No matter if the file is a tag content or attribute
The RegExp will skip any path with ":" I'm assuming that means a absolut path with protocol, like http:// or ftp:// or file://
If the path starts with 0 or more "/", there's no problem, It will work fine.

Example:
_sourceXML = updateBasePathXML(_sourceXML, "jpg|png|gif", "images/");
* If you want to affect just one type of file, use "extension" without pipe (|). ex: "swf", also you can use "\\S+" to affect any file type.
* Always include the "/" at the end of "_basepath", you can even use "../" at the beginning if you need to.

Output:
<anyTag>someImage.jpg</anyTag> ==> <anyTag>images/someImage.jpg</anyTag>
<anyTag>stuff/someImage.png</anyTag> ==> <anyTag>images/stuff/someImage.png</anyTag>
<anyTag src="/stuff/someImage.gif">Just some text</anyTag> ==> <anyTag src="images/stuff/someImage.gif">Just some text</anyTag>
<anyTag src="https://www.domain.com/img/externalImage.jpg">Just some text</anyTag> ==> <anyTag src="https://www.domain.com/img/externalImage.jpg">Just some text</anyTag> ** This will stay unaltered **

*/
function updateBasePathXML(_sourceXML:XML, _extensions:String, _basepath:String) : XML {
    var regExpStr: String = "(\"|>)(?![-\\w$\\.\+\!\*'\(\),?/]*:)(\/*)([-\\w$\\.\+\!\*'\(\),?/]+\\.+("+_extensions+"))(\"|<)";
    var regExp:RegExp = new RegExp(regExpStr, "gi");
    
    var returnStr:String = _sourceXML.toString().replace(regExp, "$1"+_basepath+"$3$5");
    
    var returnXML:XML = new XML(returnStr);
    
    return returnXML;
}

/*
This is a variation of the method above, In case you want to clean original basepath of certain file types

Example:
_sourceXML = cleanupPathsXML(_sourceXML, "jpg|png|gif");
* If you want to affect just one type of file, use "extension" without pipe (|). ex: "swf", also you can use "\\S+" to affect any file type.

Output:
<anyTag>someImage.jpg</anyTag> ==> <anyTag>someImage.jpg</anyTag>
<anyTag>stuff/someImage.png</anyTag> ==> <anyTag>someImage.png</anyTag>
<anyTag src="/stuff/someImage.gif">Just some text</anyTag> ==> <anyTag src="someImage.gif">Just some text</anyTag>
<anyTag src="https://www.domain.com/img/externalImage.jpg">Just some text</anyTag> ==> <anyTag src="https://www.domain.com/img/externalImage.jpg">Just some text</anyTag> ** This will stay unaltered **

*/
function cleanupPathsXML(_sourceXML:XML, _extensions:String) : XML {
    var regExpStr: String = "(\"|>)(?![-\\w$\\.\+\!\*'\(\),?/]*:)(\/*[-\\w$\\.\+\!\*'\(\),?/]+\/+)([-\\w$\\.\+\!\*'\(\),?/]+\\.+("+_extensions+"))(\"|<)";
    var regExp:RegExp = new RegExp(regExpStr, "gi");
    
    var returnStr:String = _sourceXML.toString().replace(regExp, "$1$3$5");
    
    var returnXML:XML = new XML(returnStr);
    
    return returnXML;
}

================

[EN] The code is part of a Class I made.
As always, this code could be improved a bit or a lot.
Hopefully this will be helpful for someone.

[ES] El codigo es parte de una Clase que hice.
Como siempre, el codigo se puede mejorar un poco o mucho.
Espero sea de utilidad para algunos.