本文整理汇总了C#中System.Text.RegularExpressions.Regex.GetGroupNames方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.GetGroupNames方法的具体用法?C# Regex.GetGroupNames怎么用?C# Regex.GetGroupNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.GetGroupNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Execute
public void Execute(string folder, int days, string dateFormat)
{
s_log.DebugFormat("Start Vaporizing Folders in {0}", folder);
var dir = new DirectoryInfo(folder);
foreach (var item in dir.GetDirectories())
{
Regex rgx = new Regex(dateFormat);
Match m = rgx.Match(item.Name);
if (m.Success)
{
var groupNames = rgx.GetGroupNames();
int hour = groupNames.Contains("hour") ? Convert.ToInt32(m.Groups["hour"].Value) : 0;
DateTime d = new DateTime(Convert.ToInt32(m.Groups["year"].Value),
Convert.ToInt32(m.Groups["month"].Value),
Convert.ToInt32(m.Groups["day"].Value),
hour, 0, 0);
if (d < DateTime.Now.AddDays(days * -1))
{
var name = item.FullName;
s_log.DebugFormat("Deleting folder {0}", name);
item.Delete(true);
s_log.DebugFormat("Finished Deleting folder {0}", name);
}
}
s_log.DebugFormat("Finished Vaporizing Folders in {0}", folder);
}
}
示例3: Rx
/// <summary>
/// Creates regular expression case
/// </summary>
/// <param name="regexPattern">Regular expression instance</param>
/// <returns>Case expression</returns>
public static Expression<Func<string, string>> Rx(Regex regexPattern)
{
var parameterExpression = Expression.Parameter(typeof (string), "strArg");
var matchExpression = Expression.Variable(typeof (Match), "match");
var retPoint = Expression.Label(typeof (string));
var successProperty = Expression.Property(matchExpression, "Success");
var resultProperty = Expression.Property(
regexPattern.GetGroupNames().Length > 1 ?
(Expression)Expression.Property(Expression.Property(matchExpression, "Groups"), "Item", Expression.Constant(1)) :
matchExpression, "Value");
var block = Expression.Block(new[] { matchExpression},
Expression.Assign(matchExpression,
Expression.Call(
Expression.Constant(regexPattern, typeof(Regex)),
typeof (Regex).GetMethod("Match", new[] {typeof (string)}),
parameterExpression)),
Expression.IfThenElse(
successProperty,
Expression.Return(retPoint, resultProperty),
Expression.Return(retPoint, Expression.Convert(Expression.Constant(null), typeof(string)))),
Expression.Label(retPoint, Expression.Default(typeof(string)))
);
return Expression.Lambda<Func<string, string>>(block, parameterExpression);
}
示例4: Solution
/// <summary>
/// Loads visual studio .sln solution
/// </summary>
/// <param name="solutionFileName"></param>
/// <exception cref="System.IO.FileNotFoundException">The file specified in path was not found.</exception>
public Solution(string solutionFileName)
{
_solutionFileName = solutionFileName;
_slnLines = new List<object>();
var slnTxt = File.ReadAllText(solutionFileName);
//Match string like: Project("{66666666-7777-8888-9999-AAAAAAAAAAAA}") = "ProjectName", "projectpath.csproj", "{11111111-2222-3333-4444-555555555555}"
var projMatcher = new Regex("Project\\(\"(?<ParentProjectGuid>{[A-F0-9-]+})\"\\) = \"(?<ProjectName>.*?)\", \"(?<RelativePath>.*?)\", \"(?<ProjectGuid>{[A-F0-9-]+})");
Regex.Replace(slnTxt, "^(.*?)[\n\r]*$", m =>
{
String line = m.Groups[1].Value;
Match m2 = projMatcher.Match(line);
if (m2.Groups.Count < 2)
{
_slnLines.Add(line);
return "";
}
var s = new SolutionProject();
// "0" - RegEx special kind of group
foreach (String g in projMatcher.GetGroupNames().Where(x => x != "0"))
s.GetType().GetField(g).SetValue(s, m2.Groups[g].ToString());
_slnLines.Add(s);
return "";
},
RegexOptions.Multiline);
}
示例5: Parse
public static Dictionary<string, string> Parse(string input, string pattern)
{
var dict = new Dictionary<string, string>();
try
{
var regex = new Regex(pattern, RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace);
string[] names = regex.GetGroupNames();
MatchCollection matches = regex.Matches(input);
foreach (Match match in matches)
{
foreach (string name in names)
{
if (dict.ContainsKey(name))
{
dict[name] += Environment.NewLine + match.Groups[name].Value;
}
else
{
dict.Add(name, match.Groups[name].Value);
}
}
}
}
catch (Exception e)
{
}
return dict;
}
示例6: regexFun
public static string regexFun(string target, string expr, object g, regexAct ra, string replStr, int replCnt, int replStart, ref MatchCollection o, int capID) {
int gn = g is int ? Int32.Parse(g.ToString()) : 0;
if (capID < 0) { capID = 0; }
Regex regex = new Regex(expr, RegexOptions.Multiline | RegexOptions.IgnoreCase);
try {
switch (ra) {
case regexAct.Match:
var varMatch = regex.Match(target);
if (!varMatch.Success) {
return null;
} else if (g is String && Array.Exists(regex.GetGroupNames(), gpnm => (gpnm == g.ToString()))) {
return varMatch.Groups[g.ToString()].Captures[capID].Value;
} else if (g is int || Int32.TryParse(g.ToString(), out gn)) {
return varMatch.Groups[gn].Captures[capID].Value;
} else {
return varMatch.Groups[0].Captures[capID].Value;
}
case regexAct.Replace:
return regex.Replace(target, (string)replStr, replCnt, replStart);
case regexAct.Matches:
var ms = regex.Matches(target);
o = ms;
return "0";
default:
return "err:-1";
}
} catch{
return "err:-2";
}
}
示例7: ProcessRegex
public bool ProcessRegex(string target, string regexExpression)
{
if (target == null)
{
target = string.Empty;
}
Regex regex = new Regex(regexExpression, RegexOptions.ExplicitCapture);
Match match = regex.Match(target);
if (!match.Success)
{
return false;
}
string[] groupNames = regex.GetGroupNames();
if (groupNames.Length > 0)
{
if (this._groups == null)
{
this._groups = new Hashtable();
}
for (int i = 0; i < groupNames.Length; i++)
{
this._groups[groupNames[i]] = match.Groups[i].Value;
}
}
return true;
}
示例8: Visionneuse
/// <summary>
/// Constructeur
/// </summary>
/// <param name="text">Texte à afficher</param>
public Visionneuse(string text)
{
InitializeComponent();
texte.Text = text;
string integers = "\\b(?:[0-9]*\\.)?[0-9]+\\b";
string Strings = "'[^']*";
string all = "\\r|\\n|\\(|\\)|'[^']*'|\\w+|\\[max\\]|\\[min\\]|\\[avg\\]|\\[count\\]|\\|/|\\.|\\{|\\}|\\[|\\]|\\+|:-|:=|<>|[(<=)(>=)^?!,@<>_~%/=:;*'&-]{1}?|\\$|\\?}";
string Comments = @"|/\*(?>(?:(?>[^*]+)|\*(?!/))*)\*/";// matches multiline comments
string reg = "--|" + integers + "|" + Strings + "|" + all;
Regex rg = new Regex(reg + Comments, RegexOptions.IgnoreCase);
MatchCollection mc_ = rg.Matches(texte.Text);
string[] a = rg.GetGroupNames();
int j = 0;
while (j < mc_.Count)
{
if (mc_[j].Value == "--")
{
while (mc_[j].Value != "\r")
{
texte.SelectionStart = mc_[j].Index;
texte.SelectionLength = mc_[j].Length;
texte.SelectionFont = new Font("Courrier", 10, FontStyle.Italic);
texte.SelectionColor = CommentColor;
j++;
}
}
ColorSQLToken(mc_[j]);
j++;
}
}
示例9: Match
public static IEnumerable Match(SqlString pattern, SqlString subject)
{
var list = new List<MatchContent>();
var regex = new Regex(pattern.Value);
var match = regex.Match(subject.Value);
var groupNames = regex.GetGroupNames();
var num = 0;
while (match.Success)
{
num++;
var array = groupNames;
foreach (var text in array)
{
list.AddRange(match.Groups[text].Captures
.Cast<Capture>()
.Select(capture =>
new MatchContent
{
MatchNumber = num,
GroupName = text,
CaptureNumber = capture.Index,
Value = capture.Value
}));
}
match = match.NextMatch();
}
return list;
}
示例10: FilterUsingRule
/// <summary>
/// 根据规则, 过滤出结果
///
/// </summary>
/// <param name="rawContent"></param>
/// <returns></returns>
public override string FilterUsingRule(ref string rawContent)
{
string filteredContent = string.Empty;
Regex reg = new Regex(RegexExp, RegexOptions.Singleline);
string[] groupNames = reg.GetGroupNames();
MatchCollection matchs = reg.Matches(rawContent);
foreach (Match m in matchs)
{
//从原始内容中删除已经提取的内容
if (m.Value == string.Empty) continue;
rawContent = rawContent.Replace(m.Value, string.Empty);
//继续提取精确内容,通过regexgroup
for (int i = 0; i < m.Groups.Count; i++)
{
string groupName = groupNames[i];
int demo;
if (!int.TryParse(groupName, out demo))
{
Group g = m.Groups[groupNames[i]];
filteredContent += g.Value + "||";
}
}
filteredContent += "&&";
}
return filteredContent;
}
示例11: ReplaceUsingFunction
internal ReplaceUsingFunction(Regex regex, ScriptFunction function, string source)
{
this.function = function;
this.cArgs = function.GetNumberOfFormalParameters();
bool flag = (function is Closure) && ((Closure) function).func.hasArgumentsObject;
this.groupNumbers = null;
this.source = source;
if ((this.cArgs > 1) || flag)
{
string[] groupNames = regex.GetGroupNames();
int num = groupNames.Length - 1;
if (flag)
{
this.cArgs = num + 3;
}
if (num > 0)
{
if (num > (this.cArgs - 1))
{
num = this.cArgs - 1;
}
this.groupNumbers = new int[num];
for (int i = 0; i < num; i++)
{
this.groupNumbers[i] = regex.GroupNumberFromName(groupNames[i + 1]);
}
}
}
}
示例12: Navigate
private void Navigate(string navigationState)
{
if (navigationState == currentUrl)
return;
currentUrl = navigationState;
string database = Server.DefaultDatabaseName;
var databasesMatch = databasesRegEx.Match(currentUrl);
if (databasesMatch.Success)
{
currentUrl = currentUrl.Substring(databasesMatch.Length);
database = databasesMatch.Groups[1].Value;
}
foreach (var route in Routes.OrderBy(x => x.Metadata.Index))
{
var regex = new Regex(route.Metadata.Url);
var match = regex.Match(navigationState);
if (match.Success == false)
continue;
var parameters = new Dictionary<string, string>();
foreach (var name in regex.GetGroupNames())
{
parameters[name] = match.Groups[name].Value;
}
route.Value.Navigate(database, parameters);
return;
}
}
示例13: Handle
public static bool Handle(string path)
{
var viewDispatcher = Mvx.Resolve<Cirrious.MvvmCross.Views.IMvxViewDispatcher>();
var appService = Mvx.Resolve<IApplicationService>();
if (!path.EndsWith("/", StringComparison.Ordinal))
path += "/";
foreach (var route in Routes)
{
var regex = new Regex(route.Path, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
var match = regex.Match(path);
var groups = regex.GetGroupNames().Skip(1);
if (match.Success)
{
var rec = new MvxViewModelRequest();
rec.ViewModelType = route.ViewModelType;
rec.ParameterValues = new Dictionary<string, string>();
foreach (var group in groups)
rec.ParameterValues.Add(group, match.Groups[group].Value);
appService.SetUserActivationAction(() => viewDispatcher.ShowViewModel(rec));
return true;
}
}
return false;
}
示例14: Handle
public static bool Handle(string path)
{
if (!path.EndsWith("/", StringComparison.Ordinal))
path += "/";
foreach (var route in Routes)
{
var regex = new Regex(route.Path, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
var match = regex.Match(path);
var groups = regex.GetGroupNames().Skip(1).ToList();
if (match.Success)
{
var vm = IoC.Resolve(route.ViewModelType);
foreach (var group in groups)
{
var property = vm.GetType().GetProperty(group);
if (property != null)
property.SetValue(vm, match.Groups[group].Value);
}
//appService.SetUserActivationAction(() => viewDispatcher.ShowViewModel(rec));
return true;
}
}
return false;
}
示例15: MatchAndPrintResults
private static void MatchAndPrintResults(Regex regex, string input)
{
Console.WriteLine("Regex: " + regex);
Console.WriteLine("Input: " + input);
MatchCollection matches = regex.Matches(input);
Console.WriteLine("Match Count: " + matches.Count);
int matchCounter = 0;
foreach (Match match in matches)
{
Console.WriteLine(string.Empty.PadRight(50, '='));
Console.WriteLine(" Match {0}:", ++matchCounter);
Console.WriteLine(" Value: " + match.Value);
Console.WriteLine(string.Empty.PadRight(50, '-'));
Console.WriteLine(" Groups:");
Console.WriteLine(string.Empty.PadRight(50, '-'));
foreach (string name in regex.GetGroupNames())
{
Console.WriteLine(" \"{0}\": {1}", name, match.Groups[name].Value);
}
Console.WriteLine(string.Empty.PadRight(50, '='));
}
Console.WriteLine();
}