当前位置: 首页>>代码示例>>C#>>正文


C# Regex.Matches方法代码示例

本文整理汇总了C#中System.Text.RegularExpressions.Regex.Matches方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.Matches方法的具体用法?C# Regex.Matches怎么用?C# Regex.Matches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.RegularExpressions.Regex的用法示例。


在下文中一共展示了Regex.Matches方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RowCount

 public int RowCount(string source)
 {
   Regex rowRegex = new Regex(_rowDelimiter);
   _source = source;
   _rows = rowRegex.Matches(_source);
   return _rows.Count;
 }
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:7,代码来源:DataRows.cs

示例2: LoadProjects

 private IEnumerable<string> LoadProjects(
     string solutionPath)
 {
     const string projectRegEx = "Project\\(\"\\{[\\w-]*\\}\"\\) = \"([\\w _]*.*)\", \"(.*\\.(cs|vcx|vb)proj)\"";
     var content = File.ReadAllText(solutionPath);
     var projReg = new Regex(projectRegEx, RegexOptions.Compiled);
     var matches = projReg.Matches(content).Cast<Match>();
     var projects = matches.Select(x => x.Groups[2].Value).ToList();
     for (var i = 0; i < projects.Count; ++i)
     {
         if (!Path.IsPathRooted(projects[i]))
         {
             var folderName = Path.GetDirectoryName(solutionPath);
             if (folderName != null)
                 projects[i] = Path.Combine(folderName, projects[i]);
         }
         try
         {
             projects[i] = Path.GetFullPath(projects[i]);
         }
         catch (NotSupportedException ex)
         {
             resolver_ProgressMessageEvent($"Path: {projects[i]}, Error: {ex.Message}");
         }
     }
     return projects;
 }
开发者ID:modulexcite,项目名称:ResolveUR,代码行数:27,代码来源:RemoveUnusedSolutionReferences.cs

示例3: Process

        /// <summary>
        /// Обрабатывает шаблон, вставляет значение полей моделей в макросы в шаблоне
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        protected override string Process(string content)
        {
            // Подгатавливаем данные
            var parseRegEx = new Regex(@"\$\{([A-Za-z0-9]+?)\}");
            var sb = new StringBuilder(content);

            var ti = Model.GetType();

            // Находим все вхождения макросов по регулярному выражению
            var matches = parseRegEx.Matches(content);
            foreach (Match match in matches)
            {
                var propertyName = match.Groups[1].Value;

                // Ищем свойство у модели
                var propertyInfo = ti.GetProperty(propertyName);
                if (propertyInfo == null)
                {
                    // Похоже что данное свойство у модели не найдено
                    continue;
                }
                var value = propertyInfo.GetValue(Model,null);

                // Выполняем замену
                sb.Replace(match.Value, value != null ? value.ToString() : String.Empty);
            }

            // Отдаем преобразованный результат
            return sb.ToString();
        }
开发者ID:softgears,项目名称:kartel,代码行数:35,代码来源:ParametrizedFileTemplate.cs

示例4: UpdateStatus

		public static string UpdateStatus(string status, TwUser user, string replyId)
		{
			Regex regex = new Regex(@"\[(.*?)\]");
			List<FileInfo> media = new List<FileInfo>();
			foreach (System.Text.RegularExpressions.Match match in regex.Matches(status))
			{
				status = status.Replace(match.Value, "");
				FileInfo file = new FileInfo(match.Value.Replace("[", "").Replace("]", ""));
				if (!file.Exists)
					throw new FileNotFoundException("File not found", file.FullName);
				media.Add(file);
            }

			if (media.Count > 4) //limited by the twitter API
				throw new ArgumentOutOfRangeException("media", "Up to 4 media files are allowed per tweet");

			if (user == null)
				user = TwUser.LoadCredentials();
			string encodedStatus = Util.EncodeString(status);
			
			if (media.Count == 0)
				return InternalUpdateStatus(user, encodedStatus, replyId);
			else
				return InternalUpdateWithMedia(user, encodedStatus, replyId, media);
		}
开发者ID:gitter-badger,项目名称:shelltwit,代码行数:25,代码来源:Update.cs

示例5: ShouldRegexMatchColonTerminatedFirstMultilineSlashNTerminated

 public void ShouldRegexMatchColonTerminatedFirstMultilineSlashNTerminated()
 {
   string content = string.Format("blah:{0}blah", "\n");
   Regex regex = new Regex(".*:$", RegexOptions.Multiline);
   regex.IsMatch(content).Should().BeTrue();
   regex.Matches(content).Count.Should().Be(1);
 }
开发者ID:fireball87,项目名称:Telnet,代码行数:7,代码来源:WithClient.cs

示例6: CorrectUrl

        /// <summary>
        /// Corrects the image path relative to the requested page or css where they originate from
        /// </summary>
        /// <param name="url"></param>
        /// <param name="requestPath"></param>
        /// <returns></returns>
        public static string CorrectUrl(string url, string requestPath)
        {
            var correctedImgPath = url.TrimStart('~');

            // make sure 'requestPath' starts with a '/'
            if (!requestPath.StartsWith("/"))
                requestPath = "/" + requestPath;

            if (!url.StartsWith("/") && !url.StartsWith("../"))
            {
                correctedImgPath = VirtualPathUtility.GetDirectory(requestPath) + url.TrimStart('/');
            }
            else if (url.StartsWith("../"))
            {
                var path = VirtualPathUtility.GetDirectory(requestPath);
                var regex = new Regex(@"\.\./");
                var levelUpMatches = regex.Matches(url);
                var numberOfLevelsUp = levelUpMatches.Count;
                var pathDirs = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                var newPathDirs = pathDirs.Take(pathDirs.Length - numberOfLevelsUp);
                var newPath = String.Join("/", newPathDirs).Trim();
                correctedImgPath = regex.Replace(url, "");
                correctedImgPath = String.IsNullOrEmpty(newPath) ? String.Format("/{0}", correctedImgPath) : String.Format("/{0}/{1}", newPath, correctedImgPath);
            }

            return correctedImgPath;
        }
开发者ID:jalva,项目名称:JsAndCssCombiner,代码行数:33,代码来源:ImagePathsUtility.cs

示例7: GetFieldFromXmlObject

        /// <summary>
        /// ͨ��������ʽ��ȡxml�б�ע���ֶ�
        /// ��עʾ�� [field_name]
        /// </summary>
        /// <param name="p_strObject">��������</param>
        /// <returns>�ֶμ���</returns>
        public static List<string> GetFieldFromXmlObject(string p_strObject)
        {
            List<string> _listField = new List<string>();
            Regex reg = new Regex(@"\[[^\[^\]]*\]");
            string _strXml = GetXML(p_strObject);
            int _nCount = reg.Matches(_strXml).Count;
            for (int i = 0; i < _nCount; i++)
            {
                string _strField = reg.Matches(_strXml)[i].Captures[0].Value;
                if (_strField.ToUpper().StartsWith("[COL"))
                {
                    continue;
                }
                _listField.Add(_strField);
            }
            reg = new Regex(@"\{[^\{^\}]*\}");
            //string _strXml = GetXML(p_strObject);
            _nCount = reg.Matches(_strXml).Count;
            for (int i = 0; i < _nCount; i++)
            {
                string _strValue = reg.Matches(_strXml)[i].Captures[0].Value;
                //if (_strValue.g)
                //{

                //}
                _listField.Add(_strValue);
            }
            return _listField;
        }
开发者ID:huzuohuyou,项目名称:DataUpload,代码行数:35,代码来源:ExportXml.cs

示例8: XFilterInclude

        public static string XFilterInclude(this string @string, string pattern)
        {
            if (string.Equals(@string, null))
            {
                return null;
            }

            if (string.Equals(@string, string.Empty))
            {
                return string.Empty;
            }

            var stringBuilder = new StringBuilder();
            var regEx = new Regex(pattern);

            // Check to see if their are no matching characters.
            if (regEx.Matches(@string).Count == 0)
            {
                return @string;
            }

            foreach (Match match in regEx.Matches(@string))
            {
                if (match.Value != string.Empty)
                {
                    stringBuilder.Append(match.Value);
                }
            }

            return stringBuilder.ToString();
        }
开发者ID:ThoughtDrive,项目名称:XtensionMethods,代码行数:31,代码来源:String.XFilterInclude.cs

示例9: ProcessInStream

        public override void ProcessInStream(List<TOBEntityBase> inStreamList)
        {
            Regex regx = new Regex("https?://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);

            foreach (TOBEntityBase tobEB in inStreamList)
            {
                if (tobEB.GetType() == typeof(Status))
                {
                    Status tempVar = (Status)tobEB;

                    MatchCollection matches = regx.Matches(tempVar.Text);

                    foreach (Match match in matches)
                    {
                        Uri webLink = new Uri(match.Value);

                        AddControlToPanel(CreateWebPreviewControl(tempVar.UserProfile.ScreenName, webLink));
                    }
                }

                if (tobEB.GetType() == typeof(DirectMessage))
                {
                    DirectMessage tempDM = (DirectMessage)tobEB;
                    MatchCollection matchesDM = regx.Matches(tempDM.Text);
                    foreach (Match match in matchesDM)
                    {
                        Uri webLink = new Uri(match.Value);
                        AddControlToPanel(CreateWebPreviewControl(tempDM.UserProfile.ScreenName,webLink));
                    }
                }
            }

            return;
        }
开发者ID:ankitb,项目名称:TweetOBox,代码行数:34,代码来源:WebPreview.cs

示例10: NumericalSort

        public static void NumericalSort(string[] ar)
        {
            Regex rgx = new Regex("([^0-9]*)([0-9]+)");
            Array.Sort(ar, (a, b) =>
            {
                var ma = rgx.Matches(a);
                var mb = rgx.Matches(b);

                // KBR 20150209 'CH' and 'Ch'
                // KBR 20140907 might not be numeric!
                if (ma.Count != mb.Count)
                    return string.Compare(a, b, StringComparison.OrdinalIgnoreCase);

                for (int i = 0; i < ma.Count; ++i)
                {
                    int ret = String.Compare(ma[i].Groups[1].Value, mb[i].Groups[1].Value, StringComparison.OrdinalIgnoreCase);
                    if (ret != 0)
                        return ret;

                    // KBR 20141222 integer overflow
                    ret = (int)(long.Parse(ma[i].Groups[2].Value) - long.Parse(mb[i].Groups[2].Value));
                    if (ret != 0)
                        return ret;
                }

                return 0;
            });
        }
开发者ID:kavenblog,项目名称:ComicViewer,代码行数:28,代码来源:ArchiveLoader.cs

示例11: SCPartners

        public ActionResult SCPartners()
        {
            wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadCompleted);
            // Loading model into view
            LinkedInModels lim = new LinkedInModels();

            string data = wc.DownloadString("http://www.sitecore.net/partners.aspx");
            int startIndex = data.IndexOf("<ul class=\"partner-links\">");
            data = data.Substring(startIndex, data.Length - (startIndex + 1));
            data = data.Substring(0, data.IndexOf("</ul>") + 5);

            XmlDocument doc = new XmlDocument();
            doc.Load(new StringReader(data));

            XmlNodeList nodes = doc.SelectNodes("//li");
            List<string> partnerList = new List<string>();
            foreach (XmlNode node in nodes)
            {
                string partnerLink = "http://www.sitecore.net/partners/[email protected]={{{0}}}#s=~_d0!2!1!!1!6!0!1!!2!!!2!1!0!_d2!4!764!W.+Europe+Standard+Time!%7B43ECEB4F-C3A3-4328-9BF8-7A1240818CC8%7D!%7B{0}%7D!_d6!HrFrsrErGrsryqIqxpuspvpwpDpBputpvpvpqAqxpuspvpwpCpzputpvpvpqqryqqqrsr!fvf%7C%40partnertype!_d0!3!Partners!_d8!fvf%7C%40country!{0}!_d1!43ECEB4F-C3A3-4328-9BF8-7A1240818CC8!!xqIqtGpypupvppwpupwpvppHpppwpupJpMpNpKpLpBpCpvpzpApDpFppEpqxpyprpqsq!";
                Regex regParterData = new Regex("{(.*)}");
                string partnerGuid = regParterData.Match(node.SelectSingleNode("//a").Attributes.GetNamedItem("href").Value).Value.Replace("{", "").Replace("}", "");
                partnerLink = string.Format(partnerLink, partnerGuid);

                byte[] partnerData = wc.DownloadData(new Uri(partnerLink));

                    Regex re = new Regex(@"<div class=""partner-result"">\s*(.+?)</a>\s*</div>", RegexOptions.Singleline);

                    string temp = System.Text.Encoding.UTF8.GetString(partnerData);

                    int count = re.Matches(System.Text.Encoding.UTF8.GetString(partnerData)).Count;

                    foreach (Match match in re.Matches(System.Text.Encoding.UTF8.GetString(partnerData)))
                    {
                        string tempPartnerData = match.Value;

                        //XmlDocument partnerDoc = new XmlDocument();
                        //Regex rePartner = new Regex("<div class=\"partner-img\">(.*)</div>", RegexOptions.Singleline);
                        //string partnerImage = rePartner.Match(tempPartnerData).Value;
                        //rePartner = new Regex("<div class=\"details\">(.*)</div>", RegexOptions.Singleline);
                        //string partnerDetails = rePartner.Match(tempPartnerData).Value;
                        //rePartner = new Regex("<a(.*)</a>", RegexOptions.Singleline);
                        //string partnerLink = rePartner.Match(tempPartnerData).Value;

                        //string partnerDescription = rePartner.Match(tempPartnerData).Value;
                        if (!partnerList.Contains(tempPartnerData))
                        {
                            partnerList.Add(tempPartnerData);
                        }
                    }
            }
            wc.DownloadDataCompleted -= new DownloadDataCompletedEventHandler(DownloadCompleted);

            List<string> gyutyutyut = partnerList;

            return View("LinkedIn", lim.Person);
        }
开发者ID:JoostMerkens,项目名称:LinkedInTest,代码行数:56,代码来源:HomeController.cs

示例12: GetFieldFromXml

 /// <summary>
 /// ͨ��������ʽ��ȡxml�б�ע���ֶ�
 /// ��עʾ�� [field_name]
 /// </summary>
 /// <param name="p_strObject">��������</param>
 /// <returns>�ֶμ���</returns>
 public static List<string> GetFieldFromXml(string p_strObject)
 {
     List<string> _listField = new List<string>();
     Regex reg = new Regex(@"\[[^\[^\]]*\]");
     string _strXml = GetXML(p_strObject);
     int _nCount = reg.Matches(_strXml).Count;
     for (int i = 0; i < _nCount; i++)
     {
         _listField.Add(reg.Matches(_strXml)[i].Captures[0].Value);
     }
     return _listField;
 }
开发者ID:wuhailong,项目名称:DataUpload,代码行数:18,代码来源:ExportXml.cs

示例13: GetImgTag

 /// <summary>
 /// 获取图片标志
 /// </summary>
 private string[] GetImgTag(string htmlStr)
 {
     Regex regObj = new Regex("<img.+?>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
     string[] strAry = new string[regObj.Matches(htmlStr).Count];
     int i = 0;
     foreach (Match matchItem in regObj.Matches(htmlStr))
     {
         strAry[i] = GetImgUrl(matchItem.Value);
         i++;
     }
     return strAry;
 }
开发者ID:xiaolin8,项目名称:AMS,代码行数:15,代码来源:ImageDown.cs

示例14: compress

 public string compress(string originalMessage)
 {
     string pattern = @"[aeiouAEIOU]";
     Regex r = new Regex(pattern);
     List<string> list = new List<string>();
     foreach (string s in originalMessage.Split(' '))
     {
         if (s != "")
             list.Add(s);
     }
     for (int i = 0; i < list.Count; i++)
     {
         string t1 = list[i];
         int x = r.Matches(list[i]).Count;
         if (x != list[i].Length)
         {
             int j = 0;
             string temp = "";
             string temp1 = "";
             List<string> values = new List<string>();
             List<int> indices = new List<int>();
             foreach (Match m in r.Matches(list[i]))
             {
                 values.Add(m.Value);
                 indices.Add(m.Index);
             }
             for (int b = 0; b < indices.Count; b++)
             {
                 if (indices[b] == j)
                 {
                     temp1 += values[b];
                     j++;
                 }
             }
             j = list[i].Length - 1;
             for (int a = indices.Count - 1; a >= 0; a--)
             {
                 if (indices[a] == j)
                 {
                     temp = temp.Insert(0, values[a]);
                     j--;
                 }
             }
             for (int a = 0; a < values.Count; a++)
                 list[i] = list[i].Replace(values[a], "");
             list[i] = list[i].Insert(list[i].Length, temp);
             list[i] = list[i].Insert(0, temp1);
             originalMessage = originalMessage.Replace(t1, list[i]);
         }
     }
     return originalMessage;
 }
开发者ID:Oscarbralo,项目名称:TopBlogCoder,代码行数:52,代码来源:Program.cs

示例15: FindStringInFields

        public bool FindStringInFields(string text)
        {
            Regex rx = new Regex(text, RegexOptions.Compiled | RegexOptions.IgnoreCase);
            MatchCollection matchesName = rx.Matches(this.Name);
            MatchCollection matchesURL = rx.Matches(this.URL);
            MatchCollection matchesLogin = rx.Matches(this.Login);
            MatchCollection matchesPassword = rx.Matches(this.Password);

            if (matchesName.Count > 0 || matchesURL.Count > 0 || matchesLogin.Count > 0 || matchesPassword.Count > 0)
                return true;

            return false;
        }
开发者ID:jeantoff,项目名称:pwstore,代码行数:13,代码来源:LogInfoStore.cs


注:本文中的System.Text.RegularExpressions.Regex.Matches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。