Created
December 21, 2017 00:53
-
-
Save tosipaulo/3baee544114fcc2c9e6fbae02d55357f to your computer and use it in GitHub Desktop.
Replace RegExp String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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