开发者

Regex matching of simple expression

开发者 https://www.devze.com 2023-04-09 04:09 出处:网络
I\'m new to regex and can\'t figure out how to match the following in C# using Regex.Matches left -> right

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

精彩评论

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