class1.cs

来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 47 行

CS
47
字号
using System;
using System.Text.RegularExpressions;

namespace RXOptions
{
	class RXOptionsApp
	{
		public static void PrintMatches(Regex r)
		{
			Console.WriteLine();
			string s = "The KING Was In His Counting House";
			MatchCollection mc = r.Matches(s);
			for (int i = 0; i < mc.Count; i++)
			{
				Console.WriteLine(
					"Found '{0}' at position {1}",
					mc[i].Value, mc[i].Index);
			}
		}

		[STAThread]
		static void Main(string[] args)
		{
			Regex r = new Regex("in|In|IN|iN");	// same
			PrintMatches(r);

			r = new Regex("in", RegexOptions.IgnoreCase);
			PrintMatches(r);

			r = new Regex("in", 
				RegexOptions.IgnoreCase | 
				RegexOptions.RightToLeft);
			PrintMatches(r);

			r = new Regex(
				@"in		# this is the first pattern to match
				|[aeiou]s	# or any vowel followed by 's'
				", RegexOptions.IgnorePatternWhitespace);
			PrintMatches(r);

			r = new Regex("in", RegexOptions.Compiled);
			PrintMatches(r);

		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?