Regular expression to split string and number

前端 未结 8 1917
天涯浪人
天涯浪人 2020-12-03 05:30

I have a string of the form:

codename123

Is there a regular expression that can be used with Regex.Split() to split the alphabetic part and

8条回答
  •  死守一世寂寞
    2020-12-03 05:58

    I know you asked for the Split method, but as an alternative you could use named capturing groups:

    var numAlpha = new Regex("(?[a-zA-Z]*)(?[0-9]*)");
    var match = numAlpha.Match("codename123");
    
    var alpha = match.Groups["Alpha"].Value;
    var num = match.Groups["Numeric"].Value;
    

提交回复
热议问题