Skip to content

Instantly share code, notes, and snippets.

@geraldfullam
Created October 31, 2014 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldfullam/becd97d2b3108e138dce to your computer and use it in GitHub Desktop.
Save geraldfullam/becd97d2b3108e138dce to your computer and use it in GitHub Desktop.
Common RegEx Replacements for Rich Text Editors
content = content
// Replace hypen, if between number, with en-dash
.replace(/(\d+)-(\d+)/ig, '$1–$2')
// Replace hypen, if between spaces, with em-dash
.replace(/( +)-+( +)/ig, '$1—$2')
// Replace smart double quotes with straight double quotes
.replace(/“|”|„|‟|″|‶/ig, '"')
// Replace smart single quotes and apostrophes with straight single quotes
.replace(/‘|’|‚|‛|′|‵/ig, ''')
// Trim in tags: moves leading/trailing whitespace out of tags
.replace(/(?:(<[^\/>]*>(?:<[^\/>]*>)*)(\s*))|(?:(\s*)(<\/[^>]*>(?:<\/[^>]*>)*))/ig, '$2$1$4$3');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment