Regular expression, split string by capital letter but ignore TLA

后端 未结 7 903
小蘑菇
小蘑菇 2020-11-27 13:26

I\'m using the regex

System.Text.RegularExpressions.Regex.Replace(stringToSplit, \"([A-Z])\", \" $1\").Trim()

to split strings by capital l

7条回答
  •  有刺的猬
    2020-11-27 13:31

    Note: I didn't read the question good enough, USAToday will return "Today"; so this anwser isn't the right one.

        public static List SplitOnCamelCase(string text)
        {
            List list = new List ();
            Regex regex = new Regex(@"(\p{Lu}\p{Ll}+)");
            foreach (Match match in regex.Matches(text))
            {
                list.Add (match.Value);
            }
            return list;
        }
    

    This will match "WakeOnBoot" as "Wake On Boot" and doesn't return anything on NMI or TLA

提交回复
热议问题