'VSCode snippet regex for extracting directory and replacing slashes?

I'm struggling to find a VSCode transformation regex that allows me take a string like this:
MyProject.Api/Data/RandomPath/Entities/User.ts
and produce:
MyProject.Api.Data.RandomPath.Entities

I can get this working in two passes; one to remove the last slash and filename, and another to replace the slashes with dots. Unfortunately VSCode snippets don't allow chaining, and I haven't been able to figure out how to combine these two passes into one.

Any help would be great, thanks!



Solution 1:[1]

I got it! It's not pretty; but here it is as follows:

/[\\/\\\\]\\w+\\.\\w+$|(\\w+)(?:[\\/\\\\]\\w+\\.\\w+$)|(\\w+(\\.\\w+)?)|\\.|[\\/\\\\]/${2}${2:+.}${1}/g

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1