Not only did I understand a little less than half of it in regulars, I also complicated the task n-times myself! In the text, the paths to the image files to the new paths are replaced, in addition, these updated paths are again used to copy the file data. I replaced the ways as follows:
$text = preg_replace("#images/(.*)'#" , "/anotherDir/images/$1'",$text);
It may be clumsy, but it works. In the following lines of code you need to copy the files involved in the renaming to the above directory. Those. you need to somehow save all these $ 1 for further use. I generally get lost. What function to apply. Whether preg_match_all whether ... well, tell me who can! At least the course of the decision.