The key point here: you do that by clarifying your requirements.
You have to specify: how many underscore characters are valid? Always 5? Or 3,5,7? Or, even numbers? 4,6? When you clarified that, you can then "define" what "middle" means to you. How long are the other parts of the input strings!?
The rest is then straight forward, but depends on your exact requirements.
If "always 5", you could simply use indexOf() repeatedly to identify the third underscore, and then "substring" manually before/after that.
Alternatively, just split by "_", and then manually merge back those parts they should sit together because "not in the middle".