Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.steveash.bushwhacker.util;
 
 
 
 
 import static com.google.common.base.CharMatcher.anyOf;
import static com.google.common.base.CharMatcher.inRange;
import static org.apache.commons.lang3.StringUtils.replace;

Author(s):
Steve Ash
public class WildcardMatcher {
  private static final CharMatcher validChars =
      inRange('a''z').or(inRange('0''9')).or(inRange('A','Z')).or(anyOf(".?*():"));
  public static Pattern compileWildcardPattern(String pattern) {
    if (!.matchesAllOf(pattern)) {
      throw new IllegalArgumentException("Cannot match the pattern \"" + pattern +
                                         "\" because some of the characters in the pattern are not "
                                         + "valid");
    }
    pattern = replace(pattern".""\\.");
    pattern = replace(pattern"(""\\(");
    pattern = replace(pattern")""\\)");
    pattern = replace(pattern"?"".?");
    pattern = replace(pattern"*"".*");
    return Pattern.compile(pattern.);
  }
New to GrepCode? Check out our FAQ X