开发者

Regex matching of simple expression

I'm new to regex and can't figure out how to match the following in C# using Regex.Matches

left -> right

I trie开发者_StackOverflow中文版d "(\w) -> (\w)" but I think I'm way off.


Not way off, you need:

(\w+) -> (\w+)

I would recommend this guide for learning regex.


Match m = Regex.Match("left -> right", @"(\w+) -> (\w+)");

Console.WriteLine(m.Groups[1]);  //left
Console.WriteLine(m.Groups[2]);  //right
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜