zoukankan      html  css  js  c++  java
  • 常考题:正则表达式 寻找所有以某个字符串开头以某个字符串结尾的所有中间字符串

    以下是字符串开头为start,字符串结尾为end,查找出现在他们中间所有的字符串

     protected void Page_Load(object sender, EventArgs e)
            {
                var start = "@";
                var end = "#";
                var source = "@123# @456# @";
                var reg = new System.Text.RegularExpressions.Regex("@(.+?)#");
                var matchs = reg.Matches(source);
                var result = new System.Collections.Generic.List <string>();
                foreach (System.Text.RegularExpressions.Match m in matchs)
                {
                    result.Add(m.Groups[1].Value);
                }
            }

    输出结果:

    123

    456

  • 相关阅读:
    LeetCode-434-字符串中的单词数
    LeetCode-415-字符串相加
    字符串
    序列
    元组
    列表
    repr()与str的区别
    输出函数print()
    输入函数input()
    MySQL中快速复制数据表方法汇总
  • 原文地址:https://www.cnblogs.com/wangyhua/p/4050656.html
Copyright © 2011-2022 走看看