How to redirect any URL with a subtopic to URL without one

I understand the title is not very descriptive. Here is what I mean.

I have urls like this:

/brain/music/music-note
/brain/sport/sport-note
etc.

I want them to be redirected to

/brain/music-note
/brain/sport-note
etc.

Here is what I have now:

[[redirects]]
  from = "/brain/:category/*"
  to = "/brain/:splat"

This doesn’t work. As far as I understand, the “splat” takes care of the star (any path). With :category I was hoping it would pick up the part of the path and drop it since it is not mentioned in the “to” section.

What is the syntax for the desired behavior? Is it even possible?

Thanks a ton in advance.

My netlify site is https://rasulkireev.com

My example will be using _redirects syntax but the same principle applies:
/brain/music/* /brain/:splat

That will strip out the undesired /music part from the URL!

@Pie

Yes, but how can I “abstractionalize” this. I want any sub-directory to be stripped out (music, sport, business, etc.)

I don’t believe this will work without having a placeholder available in the from and to parts of the redirect.

Therefore, I think the best thing to do would be to add the sub-directory as a query parameter:

/brain/:subdir/:path/* /brain/:path/:splat?:subdir

And the query parameter can remain unused.

If you still have content at the original path, you may need to do this:

/brain/:path/:splat?:subdir /brain/:path/:splat?:subdir 200!
/brain/:subdir/:path/* /brain/:path/:splat?:subdir 301!

The first rule would prevent the second one from looping, because the first one needs forcing (if content is at the original path).

Let me know if this works for you!