public static boolean wildCardMatch ( String text , String pattern ) { logger . entering ( new Object [ ] { text , pattern } ) ; Preconditions . checkArgument ( text != null , "The text on which the search is to be run cannot be null." ) ; Preconditions . checkArgument ( pattern != null , "The search pattern cannot be null." ) ; // Create the cards by splitting using a RegEx. If more speed // is desired, a simpler character based splitting can be done. String [ ] cards = pattern . split ( "\\*" ) ; // Iterate over the cards. for ( String card : cards ) { int idx = text . indexOf ( card ) ; // Card not detected in the text. if ( idx == - 1 ) { logger . exiting ( false ) ; return false ; } // Move ahead, towards the right of the text. text = text . substring ( idx + card . length ( ) ) ; } logger . exiting ( true ) ; return true ; }
Performs a wild - card matching for the text and pattern provided .