Skip to content

Instantly share code, notes, and snippets.

@tosipaulo
Created December 21, 2017 00:53
Show Gist options
  • Save tosipaulo/3baee544114fcc2c9e6fbae02d55357f to your computer and use it in GitHub Desktop.
Save tosipaulo/3baee544114fcc2c9e6fbae02d55357f to your computer and use it in GitHub Desktop.
Replace RegExp String
const regExp = /\[audiouol][0-9]{4,}\[\/audiouol\]/g;
let string = '<p><img src="http://imagem.band.com.br/novahome/17b44db0-8a3f-40c1-8d7d-9931c8a213ff.jpg" />[audiouol]234234[/audiouol]</p> [audiouol]9999999999999999999[/audiouol]<p><img src="http://adm.band.com.br/bd_images/files/real/50/f_16350.jpg" /></p>[audiouol]234234[/audiouol]<p>Lorem impsum teste aqui</p>';
/*
* output: ["[audiouol]234234[/audiouol]", "[audiouol]9999999999999999999[/audiouol]", "[audiouol]234234[/audiouol]"]
*/
const resultRegExp = string.match(regExp)
resultRegExp.map(item => {
string = string.replace(item, `<ifram src="${item.slice(10, -11)}">`);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment