C#查找以某个字母开头另一字母结尾的字符串

using System;
using System.Text.RegularExpressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string oldStr = Console.ReadLine();
            string pattern = @"BaS*cB";
            // B表示不是字边界的位置,这个串表示以a开头以c结尾的任意字符串。如hmabbccln中的abbcc这个串
            // 表示字边界,就是以a开头以c结尾的单词。如I know abc中的abc这个单词
            // S表示任何不是空白的字符。s表示任何空白字符。
MatchCollection match = Regex.Matches(oldStr, pattern, RegexOptions.IgnorePatternWhitespace |
          RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture); Console.WriteLine(match[0]); Console.ReadKey(); } } }
原文地址:https://www.cnblogs.com/fengsiyi/p/3472870.html