Skip to content

Instantly share code, notes, and snippets.

@RatoX
Created June 14, 2018 23:51
Show Gist options
  • Save RatoX/07525eef1cf0f5e3de82eef59b939893 to your computer and use it in GitHub Desktop.
Save RatoX/07525eef1cf0f5e3de82eef59b939893 to your computer and use it in GitHub Desktop.
Regex to match tags content with multiple lines
const str = 'Ola como vai <b>voce?\n Eu vou</b> <b>bem</b>'
str.replace(/<b>(.*?|[\s\S]*?)<\/b>/g, '**$1**')
// Result: "Ola como vai **voce?\n Eu vou** **bem**"
@RodolfoSilva
Copy link

Assim vai funcionar com qualquer tipo de tag.

const str = 'Ola como vai <div>voce?\n Eu vou</div> <b>bem</b>';
str.replace(/<[^>]+>([^<]+)<\/[^>]+>/g, '**$1**');
// Result: "Ola como vai **voce?\n Eu vou** **bem**"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment