Here's one ugly way:select stuff(stuff(s, idx+3, 1, '-'), idx+6, 1, '-')from ( select s, patindex('%_[0-1][0-9]_[0-3][0-9]_20[0-2][0-9]_%', s) idx from ( select 'AAAxZZZZ_7890_10_28_2014_123456.jpg' s union all select 'AAA_q10WRQ_001_10_28_2014_12.jpg' ) d ) doutput:AAAxZZZZ_7890_10-28-2014_123456.jpgAAA_q10WRQ_001_10-28-2014_12.jpg
EDIT:this version will only work with dates between years 2000 an 2029Be One with the OptimizerTG