Regular expression, split string by capital letter but ignore TLA

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

    Tomalak's expression worked for me, but not with the built-in Replace function. Regex.Replace(), however, did work.

    For i As Integer = 0 To names.Length - 1
      'Worked
      names(i) = Regex.Replace(names(i), "((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", " $1").TrimStart()
    
      ' Didn't work
      'names(i) = Replace(names(i), "([A-Z])(?=[a-z])|(?<=[a-z])([A-Z])", " $1").TrimStart()
    Next
    

    BTW, I'm using this to split the words in enumeration names for display in the UI and it works beautifully.

    0 讨论(0)
提交回复
热议问题