本文整理汇总了C#中System.Text.RegularExpressions.Regex.GroupNumberFromName方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.GroupNumberFromName方法的具体用法?C# Regex.GroupNumberFromName怎么用?C# Regex.GroupNumberFromName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了Regex.GroupNumberFromName方法的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: Parser
public Parser () {
_Regex = new Regex(
@"((?'number'(-?)[0-9]+(\.[0-9]+)?)|(?'identifier'[_A-Za-z][A-Za-z0-9_]*)|(?'operator'<=|>=|!=|[\-+/*&|^!><=.%?:@])|(?'paren'[(){}]))|(?'comma',)",
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture
);
_Group_Number = _Regex.GroupNumberFromName("number");
_Group_Identifier = _Regex.GroupNumberFromName("identifier");
_Group_Operator = _Regex.GroupNumberFromName("operator");
_Group_Paren = _Regex.GroupNumberFromName("paren");
_Group_Comma = _Regex.GroupNumberFromName("comma");
}
示例3: 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]);
}
}
}
}
示例4: ExpressionCleanerAndInputMapBuilder
/// <summary>
/// This method parses a friendly Derived Columns expression entered by the user into a Lineage-ID based
/// expression which is required by SSIS, using a regular-expression based parser.
/// Additionally, it will set the Input Column Usage for any columns found in the expression.
/// </summary>
/// <param name="expression">Expression to be parsed.</param>
/// <param name="transformation">Transformation to use for evaluating the lineage IDs</param>
/// <param name="vi">Transformation Virtual Input used to search for input columns.</param>
/// <param name="inputColumnUsageType">DTSUsageType for columns mapped in this expression.</param>
/// <returns>Expression struct with the pre-processed and post-processed expression.</returns>
public static Expression ExpressionCleanerAndInputMapBuilder(string expression, Transformation transformation, IDTSVirtualInput100 vi, DTSUsageType inputColumnUsageType)
{
Expression exp = new Expression();
exp.OriginalExpression = expression;
exp.ProcessedExpression = expression;
exp.FriendlyExpression = expression;
exp.ContainsId = false;
foreach (IDTSVirtualInputColumn100 vcol in vi.VirtualInputColumnCollection)
{
string regexString = String.Format(CultureInfo.CurrentCulture, "(\"(?:[^\"]|(?<=\\\\)\")*\")|(?<vCol>(?<[email protected]\\[?|:)\\[?\\b{0}\\b\\]?)", Regex.Escape(vcol.Name));
var regex = new Regex(regexString, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
int groupNumber = regex.GroupNumberFromName("vCol");
var processedEme = new ExpressionMatchEvaluatorStruct(groupNumber, "#" + vcol.LineageID, transformation, vi, inputColumnUsageType, vcol);
var friendlyEme = new ExpressionMatchEvaluatorStruct(groupNumber, vcol.Name, null, null, DTSUsageType.UT_IGNORED, null);
exp.ProcessedExpression = regex.Replace(exp.ProcessedExpression, new MatchEvaluator(processedEme.EvaluateMatch));
exp.FriendlyExpression = regex.Replace(exp.FriendlyExpression, new MatchEvaluator(friendlyEme.EvaluateMatch));
}
if (exp.ProcessedExpression != exp.OriginalExpression)
{
exp.ContainsId = true;
}
return exp;
}
示例5: NameLookupMatch
public void NameLookupMatch()
{
Regex regTime = new Regex(
@"(?<hour>[0-9]{1,2})([\:](?<minute>[0-9]{1,2})){0,1}([\:](?<second>[0-9]{1,2})){0,1}\s*(?<ampm>(?i:(am|pm)){0,1})");
Match mTime = regTime.Match("12:00 pm");
Assert.AreEqual(4, regTime.GroupNumberFromName("hour"), "#A1");
Assert.AreEqual(5, regTime.GroupNumberFromName("minute"), "#A1");
Assert.AreEqual(6, regTime.GroupNumberFromName("second"), "#A1");
Assert.AreEqual(7, regTime.GroupNumberFromName("ampm"), "#A1");
Assert.AreEqual("12", mTime.Groups["hour"].Value, "#B1");
Assert.AreEqual("00", mTime.Groups["minute"].Value, "#B2");
Assert.AreEqual("", mTime.Groups["second"].Value, "#B3");
Assert.AreEqual("pm", mTime.Groups["ampm"].Value, "#B4");
}
示例6: ReplaceUsingFunction
internal ReplaceUsingFunction(Regex regex, ScriptFunction function, String source) {
this.function = function;
this.cArgs = function.GetNumberOfFormalParameters();
bool hasArgumentsObject = (function is Closure) && ((Closure)function).func.hasArgumentsObject;
this.groupNumbers = null;
this.source = source;
if (this.cArgs > 1 || hasArgumentsObject) {
String[] groupNames = regex.GetGroupNames();
int cGroupNumbers = groupNames.Length - 1;
if (hasArgumentsObject) this.cArgs = cGroupNumbers+3;
if (cGroupNumbers > 0) {
if (cGroupNumbers > this.cArgs - 1)
cGroupNumbers = this.cArgs - 1;
this.groupNumbers = new int[cGroupNumbers];
for (int i = 0; i < cGroupNumbers; i++)
this.groupNumbers[i] = regex.GroupNumberFromName(groupNames[i+1]);
}
}
}
示例7: Reformat
internal static string Reformat (Regex regex, string replacement) {
replacement = JavaUtils.ReplaceAll (replacement, BACKSLASH_PATTERN, JAVA_BACKSLASH);
replacement = JavaUtils.ReplaceAll (replacement, DOUBLE_DOLLAR_PATTERN, JAVA_DOLLAR);
Pattern p = Pattern.compile (SINGLE_DOLLAR_PATTERN);
Matcher m = p.matcher ((CharSequence) (object) replacement);
StringBuffer sb = new StringBuffer ();
while (m.find ()) {
if (m.start (1) >= 0) {
int groupNumber = regex.GroupNumberFromName (m.group (1));
if (groupNumber >= 0) {
m.appendReplacement (sb, @"\$" + regex.GetJavaNumberByNetNumber (groupNumber));
continue;
}
if (int.TryParse (m.group (1), out groupNumber) && groupNumber <= regex.GroupCount) {
m.appendReplacement (sb, @"\$" + regex.GetJavaNumberByNetNumber (groupNumber));
continue;
}
m.appendReplacement (sb, JAVA_DOLLAR + "{" + m.group (1) + "}");
continue;
}
if (m.start (2) >= 0) {
int netGroupNumber = int.Parse (m.group (2));
if (netGroupNumber > regex.GroupCount) {
m.appendReplacement (sb, JAVA_DOLLAR + netGroupNumber);
continue;
}
m.appendReplacement (sb, @"\$" + regex.GetJavaNumberByNetNumber (netGroupNumber));
continue;
}
m.appendReplacement (sb, JAVA_DOLLAR);
}
m.appendTail (sb);
return sb.ToString ();
}
示例8: Run
public static void Run(string path, int field)
{
Regex regex = new Regex(@"
\G(^|,)
""
(?<field> (?> [^""]*) (?> """" [^""]* )* )
""
|
(?<field> [^"",]* )",
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
int fieldGroupIndex = regex.GroupNumberFromName("field");
using (StreamReader csv = new StreamReader(path))
{
string s;
if (field == -1)
{
while ((s = csv.ReadLine()) != null)
{
MatchCollection m = regex.Matches(s);
for (int i = 0; i < m.Count; i += 2)
s = m[i].Groups[fieldGroupIndex].Value;
}
}
else
{
while ((s = csv.ReadLine()) != null)
{
MatchCollection m = regex.Matches(s);
s = m[field << 1].Groups[fieldGroupIndex].Value;
}
}
}
}
示例9: 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 maxGroupNumber = 0;
for (int i = 1; i < groupNames.Length; i++) {
String groupName = groupNames[i];
int groupNumber = regex.GroupNumberFromName(groupName);
if (groupName.Equals(groupNumber.ToString(CultureInfo.InvariantCulture))){
if (groupNumber > maxGroupNumber)
maxGroupNumber = groupNumber;
}else{
Group group = match.Groups[groupName];
base.SetMemberValue(groupName, group.Success ? group.ToString() : null);
}
}
this.length = maxGroupNumber+1;
}
示例10: IsVersionInstalled
/// <summary>
/// Check if a specific .NET Framework version is installed.
/// </summary>
/// <param name="version">version to test</param>
/// <returns>True if installed</returns>
public static bool IsVersionInstalled(FrameworkVersions version)
{
try
{
switch (version)
{
case FrameworkVersions.Mono_2_4:
if (!string.IsNullOrEmpty(MonoVersion))
{
var regex = new Regex(@"^Mono (?<major>\d+)\.(?<minor>\d+)(\..*)?$");
if (regex.IsMatch(MonoVersion))
{
var items = regex.Split(MonoVersion);
var major = Convert.ToInt32(items[regex.GroupNumberFromName("major")]);
var minor = Convert.ToInt32(items[regex.GroupNumberFromName("minor")]);
return (major == 2 && minor >= 4) || (major >= 3);
}
}
break;
default:
var masterKey = Registry.LocalMachine.OpenSubKey(RegLocation);
if (masterKey != null)
{
var subKeyNames = masterKey.GetSubKeyNames();
if (subKeyNames.Any(ver => ver.ToLower().Replace(".", "_") == version.ToString()))
return true;
}
break;
}
}
catch (Exception)
{
return false;
}
return false;
}
示例11: GetSqlTokenParser
private static Regex GetSqlTokenParser()
{
Regex regex = _sqlTokenParser;
if (regex == null)
{
regex = new Regex(_sqlTokenPattern, RegexOptions.ExplicitCapture);
_commentGroup = regex.GroupNumberFromName("comment");
_identifierGroup = regex.GroupNumberFromName("identifier");
_parameterMarkerGroup = regex.GroupNumberFromName("parametermarker");
_queryGroup = regex.GroupNumberFromName("query");
_stringGroup = regex.GroupNumberFromName("string");
_otherGroup = regex.GroupNumberFromName("other");
_sqlTokenParser = regex;
}
return regex;
}
示例12: ReadAll_Regex
public static void ReadAll_Regex(DelimitedRecordReaderBenchmarkArguments args)
{
// regex from Jeffrey Friedl's Mastering Regular Expressions 2nd edition, p. 271
// does NOT handle trimming and multiline fields
Regex regex = new Regex(@"
\G(^|,)
""(?<field> (?> [^""]*) (?> """" [^""]* )* )""
| (?<field> [^"",]* )",
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
int fieldGroupIndex = regex.GroupNumberFromName("field");
using (var sr = new StreamReader(args.Path, args.Encoding, true, args.BufferSize))
{
string s;
if (args.FieldIndex < 0)
{
while ((s = sr.ReadLine()) != null)
{
MatchCollection mc = regex.Matches(s);
for (int i = 0; i < mc.Count; i += 2)
s = mc[i].Groups[fieldGroupIndex].Value;
}
}
else
{
while ((s = sr.ReadLine()) != null)
{
MatchCollection mc = regex.Matches(s);
for (int i = 0; i < args.FieldIndex + 1; i++)
s = mc[i * 2].Groups[fieldGroupIndex].Value;
}
}
}
}
示例13: Instance_Deny_Unrestricted
public void Instance_Deny_Unrestricted ()
{
Regex r = new Regex (String.Empty);
Assert.AreEqual (RegexOptions.None, r.Options, "Options");
Assert.IsFalse (r.RightToLeft, "RightToLeft");
Assert.AreEqual (1, r.GetGroupNames ().Length, "GetGroupNames");
Assert.AreEqual (1, r.GetGroupNumbers ().Length, "GetGroupNumbers");
Assert.AreEqual ("0", r.GroupNameFromNumber (0), "GroupNameFromNumber");
Assert.AreEqual (0, r.GroupNumberFromName ("0"), "GroupNumberFromName");
Assert.IsTrue (r.IsMatch (String.Empty), "IsMatch");
Assert.IsTrue (r.IsMatch (String.Empty, 0), "IsMatch2");
Assert.IsNotNull (r.Match (String.Empty), "Match");
Assert.IsNotNull (r.Match (String.Empty, 0), "Match2");
Assert.IsNotNull (r.Match (String.Empty, 0, 0), "Match3");
Assert.AreEqual (1, r.Matches (String.Empty).Count, "Matches");
Assert.AreEqual (1, r.Matches (String.Empty, 0).Count, "Matches2");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, new MatchEvaluator (Evaluator)), "Replace");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, new MatchEvaluator (Evaluator), 0), "Replace2");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, new MatchEvaluator (Evaluator), 0, 0), "Replace3");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, String.Empty), "Replace4");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, String.Empty, 0), "Replace5");
Assert.AreEqual (String.Empty, r.Replace (String.Empty, String.Empty, 0, 0), "Replace6");
Assert.AreEqual (2, r.Split (String.Empty).Length, "Split");
Assert.AreEqual (2, r.Split (String.Empty, 0).Length, "Split2");
Assert.AreEqual (2, r.Split (String.Empty, 0, 0).Length, "Split3");
Assert.AreEqual (String.Empty, r.ToString (), "ToString");
}
示例14: GetNumberFromCode
protected static int GetNumberFromCode(String mask, String code)
{
var numberRegex = new Regex(mask);
var numberMatch = numberRegex.Match(code);
var s = numberMatch.Groups[numberRegex.GroupNumberFromName("number")].Value;
var numberByCode = 0;
if (!int.TryParse(s, out numberByCode))
{
throw new Exception("Маска нумератора для объекта не содержит номера");
}
return numberByCode;
}
示例15: GetSqlTokenParser
private static Regex GetSqlTokenParser()
{
Regex regex = _sqlTokenParser;
if (regex == null)
{
regex = new Regex(_sqlTokenPattern, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
_identifierGroup = regex.GroupNumberFromName("identifier");
_quotedidentifierGroup = regex.GroupNumberFromName("quotedidentifier");
_keywordGroup = regex.GroupNumberFromName("keyword");
_stringGroup = regex.GroupNumberFromName("string");
_otherGroup = regex.GroupNumberFromName("other");
_sqlTokenParser = regex;
}
return regex;
}