2019年12月9日 星期一

Views

[開發問題] C# 正則表達式的用法

1.何謂正則表達式
  http://www1.nttu.edu.tw/klou/course/921/js/09-regular.htm

2. 程式碼練習
 
using System;

     using System.Text.RegularExpressions;     

     public class Program

    {
       public static void Main()

      {

         string input = "%abqw-_1";
         string pattern = @"^[a-z0-9-_%]*$";(表示開頭(^)到結尾($)可以是比對到多次的a-z或0-9或一槓(-)或底線(_)
         或百分比(%))

          foreach (Match match in Regex.Matches(input, pattern))

           Console.WriteLine(match.Value);  

       }

    }

3. 練習教程
  https://www.runoob.com/csharp/csharp-regular-expressions.html