普通的前pression来分割字符串和数字 [英] Regular expression to split string and number

查看:105
本文介绍了普通的前pression来分割字符串和数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有格式的字符串:

codename123

有没有可以用<一个使用常规的前pression href=\"http://msdn.microsoft.com/en-us/library/system.text.regularx$p$pssions.regex.split.aspx\"><$c$c>Regex.Split()以字母部分和数字部分分成两个元素的字符串数组?

Is there a regular expression that can be used with Regex.Split() to split the alphabetic part and the numeric part into a two-element string array?

推荐答案

我知道你问的拆分的方法,但作为替代,你可以使用命名捕获组:

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

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

var alpha = match.Groups["Alpha"].Value;
var num = match.Groups["Numeric"].Value;

这篇关于普通的前pression来分割字符串和数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆