Replace with REGEX and function JOIN

Replace with REGEX and function JOIN

by João Paulo Rezende da Silva

JavaScript

let originalText = "teste 1 teste 1 teste teste 1 ";
let splitText = originalText.split("1 ").join("");

document.write(`Texto original "${originalText}"`);
document.write("<br><br>");
document.write(`Texto aplicando replace com join ${splitText}`);

const regex = /1 /gi;
let replaceText = originalText.replace(new RegExp('1 ','g'), '');
document.write("<br><br>");
document.write(`Texto aplicando replace com regex ${replaceText}`);

let replaceAllText = originalText.replaceAll(regex,'');

document.write(`Texto original "${originalText}"`);
document.write("<br><br>");
document.write(`Texto aplicando replaceAll com regex ${replaceAllText}`);