group() public method

public group ( ) : global::java.lang.String
return global::java.lang.String
Exemplo n.º 1
0
		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);
		}
Exemplo n.º 2
0
		internal static void ReplaceMatch (string replacementPattern, Matcher match, StringBuffer sb, string input, PatternData patternData) {

			replacementPattern = JavaUtils.ReplaceAll (replacementPattern, COPY_ENTIRE_MATCH_PATTERN, match.group ());
			replacementPattern = JavaUtils.ReplaceAll (replacementPattern, INPUT_BEFORE_MATCH_PATTERN, input.Substring (0, match.start ()));
			replacementPattern = JavaUtils.ReplaceAll (replacementPattern, INPUT_AFTER_MATCH_PATTERN, input.Substring (match.end ()));
			replacementPattern = JavaUtils.ReplaceAll (replacementPattern, INPUT_PATTERN, input);

			int groupsNumber = match.groupCount ();
			if (groupsNumber > 0) {
				Pattern p = Pattern.compile (LAST_CAPTURED_GROUP_PATTERN);
				Matcher m = p.matcher ((CharSequence) (object) replacementPattern);
				if (m.find ()) {
					while (groupsNumber > 0) {
						if (match.start (patternData.NetToJavaNumbersMap [groupsNumber]) >= 0) {
							break;
						}
						--groupsNumber;
					}
					if (groupsNumber > 0) {
						replacementPattern = m.replaceAll (match.group (patternData.NetToJavaNumbersMap [groupsNumber]));
					}
				}
			}

			match.appendReplacement (sb, replacementPattern);
		}
Exemplo n.º 3
0
		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);
		}