Java examples for java.util.regex:Match Word
is Package Declaration by regex
//package com.java2s; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String line = "java2s.com"; System.out.println(isPackageDeclaration(line)); }//from ww w . ja va2 s.c o m public static final Pattern PACKAGE_PATTERN = Pattern .compile("^package.*"); static boolean isPackageDeclaration(String line) { return PACKAGE_PATTERN.matcher(line).matches(); } }