const regex = /^<tr.*?>(?:<td>.*?<\/td>){2}<td>(.*?)<\/td><td>.*?<\/td><td>(.*?)<\/td>.*?<a href=".*?_(.*?)_(.*?)\.html.*$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^<tr.*?>(?:<td>.*?<\\\/td>){2}<td>(.*?)<\\\/td><td>.*?<\\\/td><td>(.*?)<\\\/td>.*?<a href=".*?_(.*?)_(.*?)\\.html.*$', 'gm')
const str = `<tr><td><small>1</small></td><td>Kalisz</td><td>62-800</td><td>Poland</td><td>Greater Poland</td><td>Kalisz</td><td>Kalisz<tr><td></td><td colspan=6> <a href="/maps/browse_51.75_18.087.html" rel="nofollow"><small>51.75/18.087</small></a></td></tr>
<tr class="odd"><td><small>2</small></td><td>Piotrków Trybunalski</td><td>97-300</td><td>Poland</td><td>Łódź Voivodeship</td><td>Piotrków Trybunalski</td><td>Piotrków Trybunalski<tr class="odd"><td></td><td colspan=6> <a href="/maps/browse_51.411_19.689.html" rel="nofollow"><small>51.411/19.689</small></a></td></tr>
<tr><td><small>3</small></td><td>Toruń</td><td>87-100</td><td>Poland</td><td>Kujawsko-Pomorskie</td><td>Toruń</td><td>Toruń<tr><td></td><td colspan=6> <a href="/maps/browse_53.021_18.623.html" rel="nofollow"><small>53.021/18.623</small></a></td></tr>`;
const subst = `$2;$1;$3\/$4`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions