Split Camel Case with regex - CSharp System.Text.RegularExpressions

CSharp examples for System.Text.RegularExpressions:Split String

Description

Split Camel Case with regex

Demo Code


using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;

public class Main{
        // http://stackoverflow.com/a/5796793
        public static string SplitCamelCase(this string str)
        {//w  ww.  j  a  v a 2s .c o  m
            return Regex.Replace(
                Regex.Replace(
                    str,
                    @"(\P{Ll})(\P{Ll}\p{Ll})",
                    "$1 $2"
                ),
                @"(\p{Ll})(\P{Ll})",
                "$1 $2"
            );
        }
}

Related Tutorials