本文整理汇总了C#中System.Text.RegularExpressions.Match类的典型用法代码示例。如果您正苦于以下问题:C# Match类的具体用法?C# Match怎么用?C# Match使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Match类属于System.Text.RegularExpressions命名空间,在下文中一共展示了Match类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CleanupMatch
private static string CleanupMatch(Match match)
{
if(match.Groups["a"].Success)
return match.Groups["a"].Value.ToUpper();
return match.Groups["b"].Success ? match.Groups["b"].Value : string.Empty;
}
示例2: Handle
public string Handle(string input, Match match, IListener listener)
{
var query = match.Groups[1].Value;
var tl = new TorrentLeech();
var results = tl.Search(query);
var res = string.Empty;
var count = 0;
foreach(var result in results)
{
if (count > 7)
break;
res += count++ + ": " + result.Title + ": " + result.Size + " MB" + Environment.NewLine;
}
Brain.Pipe.ListenNext((input2, match2, listener2) =>
{
if (match2.Value == "cancel" || match2.Value == "none" || match2.Value == "nevermind")
return "Cancelled";
var index = -1;
int.TryParse(match2.Groups[1].Value, out index);
if (index == -1 || index >= results.Count)
return "Cancelled";
var selected = results[index];
selected.Download();
return "Downloading: " + selected.Friendly;
}, "cancel|none|nevermind", @"download (\d+)");
return res;
}
示例3: InjectAssets
protected string InjectAssets(string markup, Match match)
{
if (match == null)
{
return markup;
}
using (var writer = new StringWriter())
{
writer.Write(markup.Substring(0, match.Index));
WriteLinks(writer, @"<link type=""text/css"" rel=""stylesheet"" href=""{0}"" />",
Compressor.CompressCss(GetSources(CssLinks)));
WriteInlines(writer, "<style>", "</style>", CssInlines);
WriteLinks(writer, @"<script type=""text/javascript"" src=""{0}""></script>",
Compressor.CompressJavascript(GetSources(JavascriptLinks)));
WriteInlines(writer, @"<script type=""text/javascript"">", "</script>", JavascriptInlines);
WriteInlines(
writer,
@"<script type=""text/javascript"">jQuery(document).ready(function () {",
"});</script>",
DomReadyInlines);
writer.Write(markup.Substring(match.Index));
return writer.ToString();
}
}
示例4: Handle
public IEnumerable<string> Handle(string input, Match match, IListener listener)
{
var tl = new TorrentLeech();
var movies = tl.GetEntries(TorrentLeech.Movies).Distinct().Take(20).ToArray();
var names = movies.Select(o => o.Friendly).ToArray();
Brain.Pipe.ListenOnce((i, m, l) =>
{
var movie = m.Groups[1].Value;
var entry = movies.FirstOrDefault(o => o.Friendly.ToLower().Contains(movie));
if(entry == null)
return;
if(!entry.Download())
{
Brain.Pipe.ListenNext((s, match1, listener1) =>
{
if (match1.Value == "yes")
{
entry.Download(true);
listener1.Output(Speech.Yes.Parse());
listener1.Output("I shall redownload it.");
return;
}
listener1.Output(Speech.Yes.Parse());
listener1.Output("I won't redownload it.");
}, "yes", "no");
l.Output("You've already downloaded that sir. Do you want to redownload it?");
}
else
{
l.Output("Downloading " + entry.Friendly + "...");
}
}, "download (.+)");
yield return "Here are the latest films. Do you want to download any of them?";
yield return string.Join(", ", names) + "\r\n";
}
示例5: Transform
public void Transform(Match match, MarkdownReplacementArgs args)
{
args.Output.Append("<p>");
args.Encoding.Transform(args, match.Matches[0]);
args.Output.AppendUnixLine("</p>");
args.Output.AppendUnixLine();
}
示例6: OnFieldMatch
protected override NextInstruction OnFieldMatch(RecorderContext context, string source, ref Match match)
{
var ins=baseRecorder.OnFieldMatchPublic(context, source, ref match);
if (ins == NextInstruction.Return)
context.FieldBuffer[context.SourceHeaderInfo["__full_text"]] = source;
return ins;
}
示例7: TranslateLambda
public override string TranslateLambda( string codeLine, Match lambdaMatch )
{
var part0 = codeLine.Substring( 0, lambdaMatch.Groups[1].Length - 2 );
var part2 = lambdaMatch.Groups[2].Captures[0].Value;
var part1 = (lambdaMatch.Groups[1].Captures[0].Value.Trim().EndsWith( "()", StringComparison.OrdinalIgnoreCase ) ? null : ", ");
return string.Format("{0}{1}delegate{2}{{", part0, part1, part2);
}
示例8: Replace
public string Replace(Match m) {
Console.WriteLine("WARNING: Assume equality: ");
Console.WriteLine(m_SrcStr);
Console.WriteLine(m.Groups[1].Captures[0].ToString());
// this.ReplacedContent = m.Groups[1].Captures[0].ToString(); //replace text from PO filde by text from sources
return "_('" + m_ReplaceBy + "')";
}
示例9: RegexLexerContext
/// <summary>
/// Initializes a new isntance of the <see cref="RegexLexerContext"/> class
/// </summary>
/// <param name="position">the position into the source file</param>
/// <param name="match">the regular expression match data</param>
/// <param name="stateStack">The stack of states</param>
/// <param name="ruleTokenType">The token type the rule specified to emit</param>
public RegexLexerContext(int position, Match match, Stack<string> stateStack, TokenType ruleTokenType)
{
Position = position;
Match = match;
StateStack = stateStack;
RuleTokenType = ruleTokenType;
}
示例10: MatchSubstring
private static Match[] MatchSubstring(string i_source, string i_matchPattern, bool i_uniqueMatch)
{
//<note> use RegexOptions.Multiline, otherwise it will treat the whole thing as 1 string
Regex regex = new Regex(i_matchPattern, RegexOptions.Multiline);
MatchCollection matchCollection = regex.Matches(i_source);
Match[] result;
if (!i_uniqueMatch)
{
result = new Match[matchCollection.Count];
matchCollection.CopyTo(result, 0);
}
else
{
//<note> cannot use HashSet<Match> because each Match object is unique, even though they may have same value (string). Can use HashSet<string>
//SortedList is more like sorted Dictionary<key, value>
SortedList uniqueMatchCollection = new SortedList();
foreach(Match match in matchCollection)
{
if (!uniqueMatchCollection.ContainsKey(match.Value))
{
uniqueMatchCollection.Add(match.Value, match);
}
}
result = new Match[uniqueMatchCollection.Count];
uniqueMatchCollection.Values.CopyTo(result, 0); //<note> cannot use uniqueMatchCollection.CopyTo(...) since SortedList member is not type-match with destination array member
}
Console.WriteLine("Found {0} matches", result.Length);
return result;
}
示例11: BindingMatch
public BindingMatch(StepBinding stepBinding, Match match, object[] extraArguments, StepArgs stepArgs)
{
StepBinding = stepBinding;
Match = match;
ExtraArguments = extraArguments;
StepArgs = stepArgs;
}
示例12: RegExpMatch
internal RegExpMatch(ArrayPrototype parent, Regex regex, Match match, string input) : base(parent, typeof(RegExpMatch))
{
this.hydrated = false;
this.regex = regex;
this.matches = null;
this.match = match;
base.SetMemberValue("input", input);
base.SetMemberValue("index", match.Index);
base.SetMemberValue("lastIndex", (match.Length == 0) ? (match.Index + 1) : (match.Index + match.Length));
string[] groupNames = regex.GetGroupNames();
int num = 0;
for (int i = 1; i < groupNames.Length; i++)
{
string name = groupNames[i];
int num3 = regex.GroupNumberFromName(name);
if (name.Equals(num3.ToString(CultureInfo.InvariantCulture)))
{
if (num3 > num)
{
num = num3;
}
}
else
{
Group group = match.Groups[name];
base.SetMemberValue(name, group.Success ? group.ToString() : null);
}
}
this.length = num + 1;
}
示例13: MacroAttributeEvaluator
private string MacroAttributeEvaluator(Match m, bool toUnique, Item item)
{
var value = m.Groups["attributeValue"].Value.ToString();
var alias = m.Groups["attributeAlias"].Value.ToString();
if (toUnique){
int id = 0;
if (int.TryParse(value, out id))
{
Tuple<Guid,Guid> reference = PersistenceManager.Default.GetUniqueIdWithType(id);
if (reference != null)
{
value = reference.Item1.ToString();
if (this.RegisterNodeDependencies){
var provider = ItemProviders.NodeObjectTypes.GetCourierProviderFromNodeObjectType(reference.Item2);
if (provider.HasValue)
item.Dependencies.Add(value, provider.Value);
}
}
}
}else{
Guid guid = Guid.Empty;
if (Guid.TryParse(value, out guid))
{
int id = PersistenceManager.Default.GetNodeId(guid);
if (id != 0)
value = id.ToString();
}
}
// Get the matched string.
return alias + "=\"" + value + "\"";
}
示例14: MacroElementEvaluator
private string MacroElementEvaluator(Match m, bool toUnique, Item item, bool oldSyntax)
{
// Get the matched string.
var element = m.ToString();
var alias = "";
if(oldSyntax)
alias = getAttributeValue(m.ToString(), "macroAlias");
else
alias = getAttributeValue(m.ToString(), "alias");
if (!string.IsNullOrEmpty(alias))
{
var attributesToReplace = MacroAttributesWithPicker(alias);
if (this.RegisterMacroDependencies)
item.Dependencies.Add(alias, ItemProviders.ProviderIDCollection.macroItemProviderGuid);
foreach (var attr in attributesToReplace)
{
string regex = string.Format("(?<attributeAlias>{0})=\"(?<attributeValue>[^\"]*)\"", attr);
Regex rx = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
element = rx.Replace(element, match => MacroAttributeEvaluator(match, toUnique, item));
}
}
return element;
}
示例15: LinkEvaluator
private string LinkEvaluator(Match match, bool prefixLinks)
{
string mdUrlTag = match.Groups[0].Value;
string rawUrl = match.Groups[2].Value;
//Escpae external URLs
if (rawUrl.StartsWith("http") || rawUrl.StartsWith("https") || rawUrl.StartsWith("ftp"))
return mdUrlTag;
//Escape anchor links
if (rawUrl.StartsWith("#"))
return mdUrlTag;
//Correct internal image links
if (rawUrl.StartsWith("../images/"))
return mdUrlTag.Replace("../images/", "images/");
//Used for main page to correct relative links
if (prefixLinks)
{
string temp = string.Concat("/documentation/", rawUrl);
mdUrlTag = mdUrlTag.Replace(rawUrl, temp);
}
if (rawUrl.EndsWith("index.md"))
mdUrlTag = mdUrlTag.Replace("/index.md", "/");
else
mdUrlTag.TrimEnd('/');
return mdUrlTag.Replace(rawUrl, rawUrl.EnsureNoDotsInUrl());
}