@Nonnull
	@Override
	public IntRange expandRange(@Nonnull String text, int initialStart, int initialEnd) {
		String rangeText = text.substring(initialStart, initialEnd);
		int start = initialStart;
		int end = initialEnd;

		// Any rule that has backtracking/advancing needs to be expanded so that if the change breaks the start/end
		// of one of these matches, the range covers the new start/end. Primary example of this is multi-line comments.
		//
		// Example: Deleting the last '/' will expand the range forwards.
		for (RegexRule rule : rootRule.subRules()) {
			String backtrackMark = rule.backtrackMark();
			String advanceMark = rule.advanceMark();

			if (advanceMark != null && backtrackMark != null) {
				// If the range is a FULL match (from start to finish, no leading or trailing text)
				// then we do not need to change anything.
				if (RegexUtil.matches(rule.regex(), rangeText))
					break;

				// Positions of marks within the text.
				int backtrackMarkIndex = rangeText.indexOf(backtrackMark);
				int advanceMarkIndex = rangeText.indexOf(advanceMark);

				// The change in the text caused our pattern to break its original match.
				// We need to restyle a wider range.
				//
				// Advance forward if start of pattern exists, but no end of pattern exists
				if (backtrackMarkIndex > advanceMarkIndex) {
					end = Math.max(end, text.indexOf(advanceMark, end) + advanceMark.length());

					// Rules will only expand in one direction, so if we made a match by forward expansion
					// then we do not need to do backtracking for this rule.
					//
					// We are done and do not need to check any other rules.
					break;
				}

				// Advance backwards if the end of a pattern exists, but no start of pattern exists
				if (rangeText.contains(advanceMark)) {
					int index = text.substring(0, start).lastIndexOf(backtrackMark);
					if (index >= 0) {
						// Check if there is an advance mark between the 'start' and the last backtrack mark.
						// If so, then backtrack has not found something that is open to this match, as it is closed
						// by the advance mark in the middle.
						int potentialBoundOfDetectedBacktrack = text.substring(0, start).lastIndexOf(advanceMark);
						if (index > potentialBoundOfDetectedBacktrack) {
							start = index;

							// Rules will only expand in one direction, so if we made a match by backwards expansion
							// then we are done with this rule and do not need to check any other rules.
							break;
						}
					}
				}
			}
		}
		return new IntRange(start, end);
	}
@param rootRule
		Root rule, constituting a language by its sub-rules.
recaf-ui/src/main/java/software/coley/recaf/ui/control/richtext/syntax/RegexSyntaxHighlighter.java