class1.cs
来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 38 行
CS
38 行
using System;
using System.Text.RegularExpressions;
namespace Grouping
{
class GroupingApp
{
[STAThread]
static void Main(string[] args)
{
// define groups 'ing', 'in', 'n'
Regex r = new Regex("(i(n))g");
Match m = r.Match("Matching");
GroupCollection gc = m.Groups;
Console.WriteLine(
"Found {0} Groups", gc.Count);
for (int i = 0; i < gc.Count; i++)
{
Group g = gc[i];
Console.WriteLine(
"Found '{0}' at position {1}",
g.Value, g.Index);
}
Console.WriteLine();
Regex q = new Regex(
// "(?<something>[a-zA-Z_0-9]+):(?<another>\\w+)");
"(?<something>\\w+):(?<another>\\w+)");
Match n = q.Match("Salary:123456");
Console.WriteLine(
"{0} = {1}",
n.Groups["something"].Value,
n.Groups["another"].Value);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?