Added optional group by to SQL regex