Skip to content

Instantly share code, notes, and snippets.

@khannedy
Created November 3, 2014 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khannedy/2a581c24deed6732459f to your computer and use it in GitHub Desktop.
Save khannedy/2a581c24deed6732459f to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2014, Eko Khannedy and/or its affiliates. All rights reserved.
* EKO KHANNEDY PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package com.example.rule
import java.util.regex.Pattern
/**
* @author Eko Khannedy
* @since 10/27/14
*/
class Wildcard(val value: String) {
private def -?(regex: String): String =
regex.replaceAll(Pattern.quote("?"), "\\\\w")
private def -*(regex: String): String =
regex.replaceAll(Pattern.quote("*"), "\\\\w*")
def wildcard(regex: String): Boolean = {
val finalRegex = -*(-?(regex))
val result = value.matches(finalRegex)
println(s"$value matches $regex ==> $result")
result
}
}
object Wildcard {
implicit def stringToWildcard(value: String) = new Wildcard(value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment