Regular expression, split string by capital letter but ignore TLA

后端 未结 7 1076
小蘑菇
小蘑菇 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:38

    any uppercase character that is not followed by an uppercase character:

    Replace(string, "([A-Z])(?![A-Z])", " $1")
    

    Edit:

    I just noticed that you're using this for enumerations. I really do not encourage using string representations of enumerations like this, and the problems at hand is a good reason why. Have a look at this instead: http://www.refactoring.com/catalog/replaceTypeCodeWithClass.html

提交回复
热议问题