using System;
using System.Text.RegularExpressions;
public class RegexExample
{
public static void Main()
{
var text = "ThisStringHasNoSpacesASCIIButItDoesHaveCapitalsLINQ";
// Use positive lookbehind to locate all upper-case letters
// that are preceded by a lower-case letter.
var patternPart1 = "(?<=[a-z])([A-Z])";
// Used positive lookbehind and lookahead to locate all
// upper-case letters that are preceded by an upper-case
// letter and followed by a lower-case letter.
var patternPart2 = "(?<=[A-Z])([A-Z])(?=[a-z])";
var pattern = patternPart1 + "|" + patternPart2;
var rgx = new Regex(pattern);
var result = rgx.Replace(text, " $1$2");
Console.WriteLine("Input: [{0}]\nOutput: [{1}]", text, result);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGV4dC5SZWd1bGFyRXhwcmVzc2lvbnM7CgpwdWJsaWMgY2xhc3MgUmVnZXhFeGFtcGxlCnsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgIHsKICAgICAgICB2YXIgdGV4dCA9ICJUaGlzU3RyaW5nSGFzTm9TcGFjZXNBU0NJSUJ1dEl0RG9lc0hhdmVDYXBpdGFsc0xJTlEiOwoKICAgICAgICAvLyBVc2UgcG9zaXRpdmUgbG9va2JlaGluZCB0byBsb2NhdGUgYWxsIHVwcGVyLWNhc2UgbGV0dGVycwogICAgICAgIC8vIHRoYXQgYXJlIHByZWNlZGVkIGJ5IGEgbG93ZXItY2FzZSBsZXR0ZXIuCiAgICAgICAgdmFyIHBhdHRlcm5QYXJ0MSA9ICIoPzw9W2Etel0pKFtBLVpdKSI7CiAgICAgICAgCiAgICAgICAgLy8gVXNlZCBwb3NpdGl2ZSBsb29rYmVoaW5kIGFuZCBsb29rYWhlYWQgdG8gbG9jYXRlIGFsbAogICAgICAgIC8vIHVwcGVyLWNhc2UgbGV0dGVycyB0aGF0IGFyZSBwcmVjZWRlZCBieSBhbiB1cHBlci1jYXNlCiAgICAgICAgLy8gbGV0dGVyIGFuZCBmb2xsb3dlZCBieSBhIGxvd2VyLWNhc2Ug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