Skip to content

Instantly share code, notes, and snippets.

@kevinmichaelchen
Created August 25, 2015 21:46
Show Gist options
  • Save kevinmichaelchen/115418325dc8c2f6c45e to your computer and use it in GitHub Desktop.
Save kevinmichaelchen/115418325dc8c2f6c45e to your computer and use it in GitHub Desktop.
Pattern Matching in Java
class Test {
public static void main(String[] args) {
Pattern pattern = Pattern.compile( "filename\\*\\d+" );
System.out.println( pattern.matcher( "filename1" ).find() ); // false
System.out.println( pattern.matcher( "filename*1" ).find() ); // true
System.out.println( pattern.matcher( "filename*12" ).find() ); // true
System.out.println( pattern.matcher( "filename**12" ).find() ); // false
System.out.println( pattern.matcher( "filenamme*12" ).find() ); // false
System.out.println( pattern.matcher( " filename**12 =" ).find() ); // false
System.out.println( pattern.matcher( " filename**12=" ).find() ); // false
System.out.println( pattern.matcher( "filename*0=\"=?utf-8?B?Tmlt" ).find() ); // true
System.out.println( Pattern.compile( "filename\\*0" ).matcher( "filename*0=\"" ).find() ); // true
System.out.println( Pattern.compile( "filename\\*0" ).matcher( "filename*1=\"" ).find() ); // false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment