开发者

Make groups with regular expression like in perl?

In Perl if I use this regex /(\w+)\.(\开发者_JAVA百科w+)/ on the string "1A3.25D", the global vars $1 strores "1A3" and $2 stores "25D".

Is there a way to do this in C#?


Certainly, look at this example:

var pattern = @"^\D*(\d+)$";

var result = Regex.Match("Some text 10", pattern);

var num = int.Parse(result.Groups[1].Value); // 10

Group[0] is the entire match (in this case the entire line because I use ^ and $.

If you use Regex.Replace(...) you can use $X to incorporate the groups as you are used to :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜