JSFiddle - React, Tailwind, and code Playground

JavaScript

// this function transform
// Татарстан, г. Казань, ул. Баумана, 36
// to
// Татарстан, г. Казань, ул. Баумана, д. 36

function transform(addr) {
  const regEx = /((?<!(д(ом)?|стр(оение)?|\/|-)\.?\s*\d*)\d+((,?\s*(к(ор(п(ус)?)?)?\.?)\s*\d+)|(\s*[а-я])|(\s*\/\s*\d+))?\s*$)/;
  const endStr = addr.match(regEx);
  let result;
  let ret;

  if(endStr && endStr[0]) {
    result = addr.replace(endStr[0], 'д. ' + endStr[0]);
  } else {
    result = addr;
  }

  return result;
}

console.log(transform('Татарстан, г. Казань, ул. Баумана, 36'));