Skip to content

Instantly share code, notes, and snippets.

@CodeMaxter
Last active August 22, 2018 04:45
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 CodeMaxter/b53bd25df3af71d663c7845aedd7abcb to your computer and use it in GitHub Desktop.
Save CodeMaxter/b53bd25df3af71d663c7845aedd7abcb to your computer and use it in GitHub Desktop.
Regular expressions examples
// Select characters between two string
'100001000010001000'.match(/(?<=1)(0+)(?=1)/g)
// Convert a string to spinal case
function spinalCase(str) {
return str.replace(/(_?\s?([A-Z]))|[_\s]/g, (match, p1, p2, offset) => {
return (offset > 0 ? '-' : '') + (p2 ? p2.toLowerCase() : '');
});
}
console.log(spinalCase('This Is Spinal Tap'));
console.log(spinalCase('thisIsSpinalTap'));
console.log(spinalCase('The_Andy_Griffith_Show'));
console.log(spinalCase('Teletubbies say Eh-oh'));
<style>([^<]*)<\/style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment