Manipulate urls with regular expressions instead of the slip approach
You seek to:


validate the url as coming from your site domain, then
replace the 3rd and 4th directories/topics with a single/new directory/topic.


This is a simple matter of preserving the substrings that you want to keep as "capture groups" and writing the new replace substring between the two capture groups.

In my demo, the new topic will be FOO.  I'm using negated character classes to match the directory names -- this is relatively "loose" validation.  If you require a tighter validation rule, see the 2nd snippet.  Click on Run code snippet below to see the resultant output.



const regex = /^((?:https?:\/\/)(?:w{3}\.)?my-site\.com\/(?:[^/]+\/){2})[^/]+\/[^/]+(\/[^/]+)$/;
      url = 'http://www.my-site.com/topic1/Topic2/topic3/topic4/слизень',
      replacement = '$1FOO$2';

document.write(url.replace(regex, replacement));




To tighten the validation beyond non-slashes as directory substrings AND extend the characters classes to include multibyte letters, you will need to manually expand the character classes to include the letters that you expect to qualify.  Please have a read of Regular expression with the cyrillic alphabet.



const regex = /^((?:https?:\/\/)(?:w{3}\.)?my-site\.com\/(?:[À-žа-яa-z\d-]+\/){2})[À-žа-яa-z\d-]+\/[À-žа-яa-z\d-]+(\/[À-žа-яa-z\d-]+)$/i;
      url = 'http://www.my-site.com/Schnecke/to-pic2/topic3/naaktslak/слизень',
      replacement = '$1FOO$2';

document.write(url.replace(regex, replacement));