Last active
August 22, 2018 04:45
-
-
Save CodeMaxter/b53bd25df3af71d663c7845aedd7abcb to your computer and use it in GitHub Desktop.
Regular expressions examples
This file contains hidden or 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
// 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