There is a solution in this topic https://discourse.mcneel.com/t/seprate-inside-lines/104074
For the second example
TrimWithRegions_re_00_Solution.gh (31.7 KB)
But for the first case it does not quite succeed. Maybe the starting geometry is responsible
TrimWithRegions_re_.gh (26.0 KB)
Thanks to @HS_Kim