本文整理汇总了C#中System.Text.RegularExpressions.Regex.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.Cast方法的具体用法?C# Regex.Cast怎么用?C# Regex.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.Cast方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NumberOfMentionsInTweet
private static int NumberOfMentionsInTweet(string account, string tweetText)
{
const string twitterAccountPattern = @"@[A-Za-z0-9_]{1,15}";
var matches = new Regex(twitterAccountPattern).Matches(tweetText);
return
matches.Cast<object>().Count(match =>(account.IndexOf(match.ToString(), StringComparison.CurrentCultureIgnoreCase) < 0));
}
示例2: CommandHandler
public static void CommandHandler(object sender, ExecutedRoutedEventArgs ea)
{
ea.Handled = true;
var mainWindow = (MainWindow)Application.Current.MainWindow;
var tweet = ea.Parameter as Tweet ?? mainWindow.Timeline.GetSelectedTweet;
if (tweet == null) return;
if (tweet.IsDirectMessage)
{
mainWindow.Compose.ShowDirectMessage(tweet.ScreenName);
}
else
{
var matches = new Regex(@"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9_]+)")
.Matches(tweet.Text);
var names = matches
.Cast<Match>()
.Where(m => m.Groups[1].Value != tweet.ScreenName)
.Where(m => m.Groups[1].Value != Settings.Default.ScreenName)
.Select(m => "@" + m.Groups[1].Value)
.Distinct();
var replyTos = string.Join(" ", names);
var message = string.Format("@{0} {1}{2}", tweet.ScreenName, replyTos, (replyTos.Length > 0) ? " " : "");
mainWindow.Compose.Show(message, tweet.StatusId);
}
}
示例3: ResolveProjectFilesFrom
private IEnumerable<IProjectInfo> ResolveProjectFilesFrom(FileInfo file)
{
IEnumerable<IProjectInfo> projects;
using (var reader = new StreamReader(file.OpenRead()))
{
var content = reader.ReadToEnd();
var matches = new Regex("[.A-Za-z0-9\\\\]*.csproj").Matches(content);
projects = matches.Cast<Match>()
.Where(match => File.Exists(string.Format("{0}\\{1}", file.DirectoryName, match.Value)))
.Select(match => ProjectInfoFrom(file, match));
}
return projects;
}
示例4: ReplaceImg
internal static string ReplaceImg(string html)
{
var originalImages = new Regex(@"<img([^>]+)>").Matches(html);
originalImages.Cast<Match>().Each(image =>
{
var img = image.Value;
var src = AttributeParser(img, "src");
var alt = AttributeParser(img, "alt");
var title = AttributeParser(img, "title");
html = html.Replace(img, string.Format(@"![{0}]({1}{2})", alt, src, (title.Length > 0) ? string.Format(" \"{0}\"", title) : ""));
});
return html;
}
示例5: ReplaceAnchor
public static string ReplaceAnchor(string html)
{
var originalAnchors = new Regex(@"<a[^>]+>[^<]+</a>").Matches(html);
originalAnchors.Cast<Match>().Each(anchor =>
{
var a = anchor.Value;
var linkText = GetLinkText(a);
var href = AttributeParser(a, "href");
var title = AttributeParser(a, "title");
html = html.Replace(a, string.Format(@"[{0}]({1}{2})", linkText, href, (title.Length > 0) ? string.Format(" \"{0}\"", title) : ""));
});
return html;
}
示例6: ReplacePre
internal static string ReplacePre(string html)
{
var preTags = new Regex(@"<pre\b[^>]*>([\s\S]*)<\/pre>").Matches(html);
return preTags.Cast<Match>().Aggregate(html, ConvertPre);
}
示例7: SortChapterByName
internal static string SortChapterByName(MangaChapter arg)
{
var matches = new Regex(@"(([0-9])*[0-9])").Matches(arg.Name);
if (matches.Count < 1) return "";
return arg.Name.Substring(0, arg.Name.IndexOf(matches[0].Value)) + matches.Cast<Match>().Select(n => n.Value.PadLeft(3, '0')).Aggregate((m, n) => m + n);
}
示例8: GetUnsubstitutedSettings
private static IList<string> GetUnsubstitutedSettings(string content)
{
var matches = new Regex(@"(?<!`)\${([^}]*)}").Matches(content);
return (matches.Cast<object>().Select(match => match.ToString())).ToList();
}
示例9: ResolveProjectFilesFrom
private IList<IProjectFile> ResolveProjectFilesFrom(string content)
{
var matches = new Regex("[.A-Za-z0-9\\\\]*.csproj").Matches(content);
var projectFiles = matches.Cast<Match>()
.Select(match => ProjectFile.Load(string.Format("{0}\\{1}", Path, match.Value)))
.Cast<IProjectFile>().ToList();
if (projectFiles.IsEmpty()) throw new NoProjectsInSolutionComplaint(this);
return projectFiles;
}
示例10: ReplaceCode
public static string ReplaceCode(string html)
{
var singleLineCodeBlocks = new Regex(@"<code>([^\n]*?)</code>").Matches(html);
singleLineCodeBlocks.Cast<Match>().ToList().ForEach(block =>
{
var code = block.Value;
var content = GetCodeContent(code);
html = html.Replace(code, string.Format("`{0}`", content));
});
var multiLineCodeBlocks = new Regex(@"<code>([^>]*?)</code>").Matches(html);
multiLineCodeBlocks.Cast<Match>().ToList().ForEach(block =>
{
var code = block.Value;
var content = GetCodeContent(code);
content = IndentLines(content).TrimEnd() + Environment.NewLine + Environment.NewLine;
html = html.Replace(code, string.Format("{0} {1}", Environment.NewLine, TabsToSpaces(content)));
});
return html;
}