private string ReplaceGroupNumber (Matcher match, string reformattedPattern, PatternGrouping patternGrouping, RegexOptions options) { int groupNumber = int.Parse (match.group (1)); int javaGroupNumber = groupNumber; int groupCount = patternGrouping.GroupCount; if (groupCount == -1) { if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture) { groupCount = 0; } else { groupCount = JavaUtils.GroupCount (reformattedPattern); } } else { javaGroupNumber = patternGrouping.NetToJavaNumbersMap [groupNumber]; } if (groupNumber > groupCount) { return null; } return match.replaceFirst (@"\\" + javaGroupNumber); }
private string ReplaceGroupName (Matcher match, string reformattedPattern, PatternGrouping patternGrouping, RegexOptions options) { if (patternGrouping.GroupCount == -1){ return null; } string groupName = match.group (1); Pattern p = Pattern.compile (NUMBER); Matcher m = p.matcher ((CharSequence) (object) groupName); if (m.matches ()) { return ReplaceGroupNumber (match, reformattedPattern, patternGrouping, options); } if (!patternGrouping.GroupNameToNumberMap.Contains (groupName)) { return null; } int javaGroupNumber = patternGrouping.NetToJavaNumbersMap [(int) patternGrouping.GroupNameToNumberMap [groupName]]; return match.replaceFirst (@"\\" + javaGroupNumber); }