Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.editor.outline.quickoutline;
Matches a given java.lang.String against a prefix pattern. The matching algorithm will return true if the tested string starts with the given pattern. The pattern supports wildcards such as * and ?.

Peter Friese - Initial contribution and API
Sebastian Zarnekow - Javadoc, minor fixes to the matching algorithm
public class StringMatcher {
	private final String expression;
	private final boolean ignoreCase;
	private Pattern pattern;
	public StringMatcher(String patternboolean ignoreCase) {
		this. = translatePattern(pattern);
		this. = ignoreCase;

	protected String translatePattern(String pattern) {
		String expression = pattern.replaceAll("\\(""\\\\(");
		expression = expression.replaceAll("\\)""\\\\)");
		expression = expression.replaceAll("\\[""\\\\[");
		expression = expression.replaceAll("\\]""\\\\]");
		expression = expression.replaceAll("\\{""\\\\{");
		expression = expression.replaceAll("\\}""\\\\}");
		expression = expression.replaceAll("\\*"".*");
		expression = expression.replaceAll("\\?"".");
		if (!expression.startsWith("^"))
			expression = "^" + expression;
		return expression;

2.1 protected
	protected Pattern getPattern() {
		if ( == null) {
			if () {
			else {
		return ;
	public boolean match(String text) {
		return getPattern().matcher(text).find();
New to GrepCode? Check out our FAQ X