Created
November 3, 2014 17:43
-
-
Save khannedy/2a581c24deed6732459f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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