Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
(?<=(?<![<](?:pre|code)[^>]*?)[>])(?:[\s\n]*([^<]*?)[\s\n]*)(?=[<](?![\/](?:pre|code)))
/
dig

Description

Basic expression to match and/or remove whitespace and linebreaks between HTML tags via JavaScript (ECMAScript).

  • respects whitespace between <pre> and <code> tags
  • matches multiple lines around words, but not between them
  • totally not safe for use in a production environment ;)

MIT © Nicholas Berlette

Submitted by Nicholas Berlette (https://github.com/nberlette) - 2 years ago