Match a bracketed token given the start bracket and the end bracket
The result includes the brackets.
@param start
@param end
@param textProvider
@return true if match
964454
public boolean getBracketedToken(char start, char end, TextProvider textProvider)
    {
        clearLastToken(textProvider);
        clearLeadingSpaces(textProvider);
        mark(textProvider);
        if (m_debug)
			debug("testing " + start + " " + end,textProvider);
        StringBuilder sb = new StringBuilder();
        char c = getNextChar(textProvider);

        if (c != start)
        {
            reset(textProvider);
            return false;
        }
        int brackets = 0;

        while (true)
        {
            if (c == start) brackets++;
            if (c == end) brackets--;
            sb.append(c);
            if (brackets < 1) break;
            c = getNextChar(textProvider);
            if (c == 0)
            {
            	reset(textProvider);
				return false;
            }
        }
        unmark(textProvider);
        String s = sb.toString().trim();
        if (s.length() == 0) return false;
        textProvider.setLastToken(s);
        debug(textProvider);
        return true;
    }
181232
public boolean matches(CharacterIterator target, Match match) {
		int start = target.getBeginIndex();
		int end = target.getEndIndex();

		synchronized (this) {
			if (this.operations == null)
				this.prepare();
			if (this.context == null)
				this.context = new Context();
		}
		Context con = null;
		synchronized (this.context) {
			con = this.context.inuse ? new Context() : this.context;
			con.reset(target, start, end, this.numberOfClosures);
		}
		if (match != null) {
			match.setNumberOfGroups(this.nofparen);
			match.setSource(target);
		} else if (this.hasBackReferences) {
			match = new Match();
			match.setNumberOfGroups(this.nofparen);
			// Need not to call setSource() because
			// a caller can not access this match instance.
		}
		con.match = match;

		if (RegularExpression.isSet(this.options, XMLSCHEMA_MODE)) {
			int matchEnd = this.match(con, this.operations, con.start, 1,
					this.options);
			// System.err.println("DEBUG: matchEnd="+matchEnd);
			if (matchEnd == con.limit) {
				if (con.match != null) {
					con.match.setBeginning(0, con.start);
					con.match.setEnd(0, matchEnd);
				}
				con.setInUse(false);
				return true;
			}
			return false;
		}

		/*
		 * The pattern has only fixed string. The engine uses Boyer-Moore.
		 */
		if (this.fixedStringOnly) {
			// System.err.println("DEBUG: fixed-only: "+this.fixedString);
			int o = this.fixedStringTable.matches(target, con.start, con.limit);
			if (o >= 0) {
				if (con.match != null) {
					con.match.setBeginning(0, o);
					con.match.setEnd(0, o + this.fixedString.length());
				}
				con.setInUse(false);
				return true;
			}
			con.setInUse(false);
			return false;
		}

		/*
		 * The pattern contains a fixed string. The engine checks with
		 * Boyer-Moore whether the text contains the fixed string or not. If
		 * not, it return with false.
		 */
		if (this.fixedString != null) {
			int o = this.fixedStringTable.matches(target, con.start, con.limit);
			if (o < 0) {
				// System.err.println("Non-match in fixed-string search.");
				con.setInUse(false);
				return false;
			}
		}

		int limit = con.limit - this.minlength;
		int matchStart;
		int matchEnd = -1;

		/*
		 * Checks whether the expression starts with ".*".
		 */
		if (this.operations != null && this.operations.type == Op.CLOSURE
				&& this.operations.getChild().type == Op.DOT) {
			if (isSet(this.options, SINGLE_LINE)) {
				matchStart = con.start;
				matchEnd = this.match(con, this.operations, con.start, 1,
						this.options);
			} else {
				boolean previousIsEOL = true;
				for (matchStart = con.start; matchStart <= limit; matchStart++) {
					int ch = target.setIndex(matchStart);
					if (isEOLChar(ch)) {
						previousIsEOL = true;
					} else {
						if (previousIsEOL) {
							if (0 <= (matchEnd = this.match(con,
									this.operations, matchStart, 1,
									this.options)))
								break;
						}
						previousIsEOL = false;
					}
				}
			}
		}

		/*
		 * Optimization against the first character.
		 */
		else if (this.firstChar != null) {
			// System.err.println("DEBUG: with firstchar-matching: "+this.firstChar);
			RangeToken range = this.firstChar;
			for (matchStart = con.start; matchStart <= limit; matchStart++) {
				int ch = target.setIndex(matchStart);
				if (REUtil.isHighSurrogate(ch) && matchStart + 1 < con.limit) {
					ch = REUtil.composeFromSurrogates(ch,
							target.setIndex(matchStart + 1));
				}
				if (!range.match(ch)) {
					continue;
				}
				if (0 <= (matchEnd = this.match(con, this.operations,
						matchStart, 1, this.options))) {
					break;
				}
			}
		}

		/*
		 * Straightforward matching.
		 */
		else {
			for (matchStart = con.start; matchStart <= limit; matchStart++) {
				if (0 <= (matchEnd = this.match(con, this.operations,
						matchStart, 1, this.options)))
					break;
			}
		}

		if (matchEnd >= 0) {
			if (con.match != null) {
				con.match.setBeginning(0, matchStart);
				con.match.setEnd(0, matchEnd);
			}
			con.setInUse(false);
			return true;
		} else {
			con.setInUse(false);
			return false;
		}
	}
1001923
public static Boolean checkTokenBoundaries(MatchResult r, Sentence s, JCas jcas){
		Boolean beginOK = false;
		Boolean endOK = false;
	
		// whole expression is marked as a sentence
		if ((r.end() - r.start()) == (s.getEnd() -s.getBegin())){
			return true;
		}
		
		// Only check Token boundaries if no white-spaces in front of and behind the match-result
		if ((r.start() > 0) 
				&& ((s.getCoveredText().subSequence(r.start()-1, r.start()).equals(" ")))
				&& ((r.end() < s.getCoveredText().length()) && ((s.getCoveredText().subSequence(r.end(), r.end()+1).equals(" "))))) {
			return true;
		}
	
		// other token boundaries than white-spaces
		else {
			FSIterator iterToken = jcas.getAnnotationIndex(Token.type).subiterator(s);
			while (iterToken.hasNext()) {
				Token t = (Token) iterToken.next();
			
				// Check begin
				if ((r.start() + s.getBegin()) == t.getBegin()){
					beginOK = true;
				}
				// Tokenizer does not split number from some symbols (".", "/", "-", "–"),
				// e.g., "...12 August-24 Augsut..."
				else if ((r.start() > 0)
						&& ((s.getCoveredText().subSequence(r.start()-1, r.start()).equals("."))
						|| (s.getCoveredText().subSequence(r.start()-1, r.start()).equals("/")) 
						|| (s.getCoveredText().subSequence(r.start()-1, r.start()).equals("–"))
						|| (s.getCoveredText().subSequence(r.start()-1, r.start()).equals("-")))) {
					beginOK = true;
				}
			
				// Check end
				if ((r.end() + s.getBegin()) == t.getEnd()) {
					endOK = true;
				}
				// Tokenizer does not split number from some symbols (".", "/", "-", "–"),
				// e.g., "... in 1990. New Sentence ..."
				else if ((r.end() < s.getCoveredText().length()) 
						&& ((s.getCoveredText().subSequence(r.end(), r.end()+1).equals("."))
								|| (s.getCoveredText().subSequence(r.end(), r.end()+1).equals("/"))
								|| (s.getCoveredText().subSequence(r.end(), r.end()+1).equals("–")) 
								|| (s.getCoveredText().subSequence(r.end(), r.end()+1).equals("-")))) {
					endOK = true;
				}
			
				if (beginOK && endOK)
					return true;
			}
		}
		return false;
	}
216402
public static boolean matches(final String text1, final String text2, final Configuration config){
        if(config.isRegexLabelText() && text2.startsWith("/") && text2.endsWith("/")){
            return normalize(text1, config).matches(text2.substring(1, text2.length() - 1));
        } else {
            return normalize(text1, config).equals(normalize(text2, config));
//            return normalize(text1, config).equals(text2);
        }
    }
130159
public static boolean endAny(String target, List<String> endWith) {
		if (isNull(target)) {
			return false;
		}
		
		return matcher(target).ends(endWith);
	}
443068
public static boolean match(Version version, String begin, String end) {
        E.checkArgumentNotNull(version, "The version to match is null");
        return version.compareTo(new Version(begin)) >= 0 &&
               version.compareTo(new Version(end)) < 0;
    }
706786
protected boolean verifyPatternMatch(String text) {
		if (this.expectedPattern == null) {
			return false;
		}
		return this.expectedPattern.matcher(text).matches();
	}
1207121
boolean match(String candidate) {
    char[] chars = candidate.toCharArray();
    int[] cursor = new int[] {0, chars.length};
    if (!checkPrefix(chars, cursor))
      return false;
    if (prefix == suffix && midClauses == null)
      // The pattern consists only of the prefix, which must exhaust the string
      return cursor[0] == cursor[1];
    if (!checkSuffix(chars, cursor))
      return false;
    return matchMiddle(chars, cursor[0], cursor[1]);
  }
741207
private TextPosition startOf(String token, ASTNode node) {
    // try to compensate for the fact that getLastLineNumber() is sometimes wrong
    int lastLineIndex = Math.max(node.getLineNumber(), node.getLastLineNumber()) - 1;

    for (int lineIndex = lastLineIndex; lineIndex >= 0; lineIndex--) {
      int columnIndex = lineIndex == lastLineIndex ?
          lines[lineIndex].lastIndexOf(token, node.getColumnNumber() - 1) :
          lines[lineIndex].lastIndexOf(token);
      if (columnIndex != -1)
        return TextPosition.create(lineIndex + 1, columnIndex + 1);
    }

    throw new IllegalArgumentException(String.format("token %s not found in expression", token));
  }
418511
private static boolean matches16(CharSequence s, int start, final String t, int length) {
        int end = start + length;
        while (length-- > 0) {
            if (s.charAt(--end) != t.charAt(length)) {
                return false;
            }
        }
        return true;
    }
181792
public boolean quotedString(char quote,TextProvider textProvider)        
    {
        clearLastToken(textProvider);
        clearLeadingSpaces(textProvider);
        mark(textProvider);
        if (m_debug)
			debug("testing "+quote,textProvider);

        if (getNextChar(textProvider) != quote)
        {
            reset(textProvider);
            return false;
        }
        char lastChar = 0;
        char c = 0;
        StringBuilder sb = new StringBuilder();
        while (true)
        {
            lastChar = c;
            c = getNextChar(textProvider);
			if (c == 0) {
		        unmark(textProvider);
				return false;
			}
            if (c == quote && lastChar != '\\') break;
            sb.append(c);
        }
        unmark(textProvider);
        String s = sb.toString().trim();
        if (s.length() == 0) return false;
        textProvider.setLastToken(s);
        debug(textProvider);
        return true;
    }
518186
public boolean exactOrError(String match,TextProvider textProvider) 
    {
        if (!exact(match,textProvider,false))
        {
            throw new ParserException("Expected "+match,textProvider);
        }
        return true;
    }
1040206
function getMatchingParenthesis(string, startPos) {
    var length = string.length;
    var bracket = 1;
    for (var i=startPos+1; i<=length; i++) {
        if (string[i] == '(') {
            bracket += 1;
        } else if (string[i] == ')') {
            bracket -= 1;
        }
        if (bracket == 0) {
            return i;
        }
    }
}
694583
static Matcher combineAdjacentStart(Matcher matcher) {
    if (matcher instanceof SeqMatcher) {
      List<Matcher> matchers = matcher.<SeqMatcher>as().matchers();
      if (!matchers.isEmpty() && matchers.get(0) instanceof StartMatcher) {
        List<Matcher> ms = new ArrayList<>();
        ms.add(StartMatcher.INSTANCE);
        int pos = 0;
        for (Matcher m : matchers) {
          if (m instanceof StartMatcher) {
            ++pos;
          } else {
            break;
          }
        }
        ms.addAll(matchers.subList(pos, matchers.size()));
        return SeqMatcher.create(ms);
      }
    }
    return matcher;
  }
1312185
public static Boolean matches( String text , String pattern , String escapeChar )
    {
        if (pattern.length() == 0)
            return text.length() == 0 ? Boolean.TRUE : Boolean.FALSE;
        
        int textPos = 0;
        boolean startWithAny = false;
        String separators = "%_";
        if (escapeChar != null)
            separators += escapeChar;
        StringTokenizer st = new StringTokenizer(pattern,separators,true);
        boolean escapeNext = false;
        while (st.hasMoreTokens())
        {
            String subPattern = st.nextToken();
            
            if (escapeChar != null && !escapeNext && subPattern.equals(escapeChar))
            {
                escapeNext = true;
            }
            else
            if (!escapeNext && subPattern.equals("%"))
            {
                startWithAny = true;
            }
            else
            if (!escapeNext && subPattern.equals("_"))
            {
                if (textPos < text.length())
                    textPos++;
                else
                    return Boolean.FALSE;
            }
            else
            {
                if (startWithAny)
                {
                    int matchPos = text.lastIndexOf(subPattern);
                    if (matchPos == -1 || matchPos < textPos) 
                        return Boolean.FALSE;
                    textPos = matchPos + subPattern.length();
                    startWithAny = false;
                }
                else
                {
                    if (!text.startsWith(subPattern,textPos))
                        return Boolean.FALSE;
                    else
                        textPos += subPattern.length();
                }
                escapeNext = false;
            }
        }
        
        return Boolean.TRUE;
    }
1152819
protected static boolean matches( String text , String pattern , boolean ignoreCase )
    {
        if (text == null)
            return false;
        if (pattern.length() == 0)
            return text.length() == 0;
        
        int textPos = 0;
        boolean startWithAny = false;
        StringTokenizer st = new StringTokenizer(pattern,"*?",true);
        while (st.hasMoreTokens())
        {
            String subPattern = st.nextToken();
            
            if (subPattern.equals("*"))
            {
                startWithAny = true;
            }
            else
            if (subPattern.equals("?"))
            {
                if (textPos < text.length())
                    textPos++;
                else
                    return false;
            }
            else
            {
                if (startWithAny)
                {
                    textPos = indexOf(text,subPattern,textPos,ignoreCase);
                    if (textPos == -1) return false;
                    startWithAny = false;
                }
                else
                {
                    if (!startsWith(text,subPattern,textPos,ignoreCase))
                        return false;
                }
                textPos += subPattern.length();
            }
        }
        
        // Remaining text
        if (textPos < text.length())
            if (!startWithAny)
                return false;
        
        return true;
    }
625501
private boolean matchPreservesCase(List<Match> suggestionMatches, String msg) {
    if (suggestionMatches != null && !suggestionMatches.isEmpty()) {
      //PatternRule rule = (PatternRule) this.rule;
      int sugStart = msg.indexOf(SUGGESTION_START_TAG) + SUGGESTION_START_TAG.length();
      for (Match sMatch : suggestionMatches) {
        if (!sMatch.isInMessageOnly() && sMatch.convertsCase()
            && msg.charAt(sugStart) == '\\') {
          return false;
        }
      }
    }
    return true;
  }