Created
August 4, 2021 14:12
-
-
Save mattkenefick/a46017d3c2754c7ae4f21f1dde483780 to your computer and use it in GitHub Desktop.
Snippets in JavaScript: Converting PascaleCase to kebab-case
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
using System; | |
using System.Text.RegularExpressions; | |
public class Program | |
{ | |
public static void Main() { | |
string input = "MyParagraphElement"; | |
string output = Regex.Replace(input, @"([a-z0–9])([A-Z])", "$1-$2").ToLower(); | |
Console.WriteLine(output); | |
} | |
} |
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
"MyParagraphElement".replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase(); | |
// my-paragraph-element |
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
<?php | |
$input = 'MyParagraphElement'; | |
$output = strtolower(preg_replace('/([a-z0–9])([A-Z])/', '$1-$2', $input)); | |
echo $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment