Skip to content

Instantly share code, notes, and snippets.

@karimkod
Created October 30, 2020 10:28
Show Gist options
  • Save karimkod/4c68c4a3a9f013dba02bf3e15028ae5f to your computer and use it in GitHub Desktop.
Save karimkod/4c68c4a3a9f013dba02bf3e15028ae5f to your computer and use it in GitHub Desktop.
RegEx used with String.protoype.replace to replace all single quotes with double quotes in the text and ignoring single quotes used for contractions.
//Replace Single quote with double quote in a text regularExpression.
let reg = /([^\w])'(.+)'([^\w])/ig;
let text = "and then he said : 'Oh no rick, don't kill me please'. And rick replied : 'frick off kid' knowing he won't.";
let replaced = text.replace(reg, '$1"$2"$3');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment