Created
October 31, 2014 18:24
-
-
Save geraldfullam/becd97d2b3108e138dce to your computer and use it in GitHub Desktop.
Common RegEx Replacements for Rich Text Editors
This file contains 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
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