Skip to content

Instantly share code, notes, and snippets.

@benlk
Last active August 29, 2015 14:06
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 benlk/5f9f9f136f275e05eaea to your computer and use it in GitHub Desktop.
Save benlk/5f9f9f136f275e05eaea to your computer and use it in GitHub Desktop.
Why doesn't this javascript regex work?
var quoteHTML = "34. If you’re leaving scorch-marks, you need a bigger gun. ";
quoteHTML.replace(/(^\d+[.,:;](\ |\d+\ ))/m, '<span class="dnumber">$1<\/span>');
console.log(quoteHTML);
// returns '34. If you’re leaving scorch-marks, you need a bigger gun. '
// goal is to:
// - match 1. 22. 33.44 44:55 5:66 at the start of a line, followed by a space
// - wrap it in <span class="dnumber"></span>
// ideal output '<span class="dnumber">34. </span>If you’re leaving scorch-marks, you need a bigger gun. '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment