Regular expression test

by Christian Unigarro

HTML

<div class="js-text"></div>

JavaScript

const initText = 'Carrera 4a #  2345 - 32 , 54 - 535, fefwe, twr- gwg';
const text = document.querySelector('.js-text');
const rex = /[0-9]+[\s-\s]+[0-9]+/;
let textWithRex = '';
let textResult = '';

textWithRex = rex.exec(initText);

if(textWithRex != null) {
  textWithRex = textWithRex[0].replace(/\s+/g, '');
  textResult = initText.replace(rex, textWithRex);
} else {
	textResult = initText;
}

text.innerHTML = textResult;