Remove extension dates in sql server

How to remove extension dates in SQL server?
table: @t
declare @t table (a varchar(50))
insert into @t values ('c:\abc_20181008.txt')
insert into @t values ('c:\abc_xyz_20181007.dat')
insert into @t values ('c:\ab.xyz_20181007.txt')
insert into @t values ('c:\ab.xyz_20182007.txt')
insert into @t values ('c:\abcxyz_19982007.txt')

based on above data I want output like below :
filename
c:\abc.txt
c:\abc_xyz.dat
c:\ab.xyz.txt
c:\ab.xyz.txt
c:\abcxyz.txt

I tried like below :
declare @t table (a varchar(50))
insert into @t values ('c:\abc_20181008.txt')
insert into @t values ('c:\abc_xyz_20181007.dat')
insert into @t values ('c:\ab.xyz_20181007.txt')
insert into @t values ('c:\ab.xyz_20182007.txt')
insert into @t values ('c:\abcxyz_19982007.txt')
select replace(SUBSTRING(a,1,CHARINDEX('2',a) - 1) + SUBSTRING(a,len(a)-3,LEN(a)),'_.','.') from @t
but above query is not given expected result.
please tell me how to achive this task in sql server

a_new is the new value:

--added these rows to demonstrate if no "_" before the date, or no date all all.
insert into @t values ('c:\abcxyz19982007.txt')
insert into @t values ('c:\abcxyzqrst.txt')

select a,
    case when yyyymmdd_loc = 0 then a
    else stuff(a, yyyymmdd_loc - yyyymmdd_has_underscore_before, 8 + yyyymmdd_has_underscore_before, '') end as a_new
from @t
cross apply (
    select patindex('%[12][0-9][0-9][0-9][0123][0-9][01][0-9]%', a) as yyyymmdd_loc
) as alias1
cross apply (
    select case when yyyymmdd_loc > 0 and substring(a, yyyymmdd_loc - 1, 1) = '_' 
        then 1 else 0 end as yyyymmdd_has_underscore_before
) as alias2
DECLARE @t table (a varchar(50));
INSERT @t 
VALUES ('c:\abc_20181008.txt')
     , ('c:\abc_xyz_20181007.dat')
     , ('c:\ab.xyz_20181007.txt')
     , ('c:\ab.xyz_20182007.txt')
     , ('c:\abcxyz_19982007.txt') ;
SELECT Left(a, CharIndex('_', a)-1)+Right(a, 4) filename 
FROM @t;

image