Example usage for java.util.regex Matcher matches

List of usage examples for java.util.regex Matcher matches

Introduction

In this page you can find the example usage for java.util.regex Matcher matches.

Prototype

public boolean matches() 

Source Link

Document

Attempts to match the entire region against the pattern.

Usage

From source file:RegExpr.java

public static void main(String args[]) {
    Pattern pat;/*from   w w  w . ja v a 2 s  .  co m*/
    Matcher mat;
    boolean found;

    pat = Pattern.compile("Java");
    mat = pat.matcher("Java");

    found = mat.matches();

    if (found)
        System.out.println("Matches");
    else
        System.out.println("No Match");

    mat = pat.matcher("Java 2");

    found = mat.matches();

    if (found)
        System.out.println("Matches");
    else
        System.out.println("No Match");
}

From source file:MainClass.java

public static void main(String args[]) {
    Pattern pat;/*from ww w .  ja  v  a  2s . co m*/
    Matcher mat;
    boolean found;

    pat = Pattern.compile("Java");
    mat = pat.matcher("Java");

    found = mat.matches();

    if (found)
        System.out.println("Matches");
    else
        System.out.println("No Match");

    System.out.println();

    mat = pat.matcher("Java 2");

    found = mat.matches();

    if (found)
        System.out.println("Matches");
    else
        System.out.println("No Match");
}

From source file:com.opengamma.bbg.loader.BloombergSwaptionFileLoader.java

/**
 * Little util to parse swaption tickers into a csv for further analysis.
 * @param args command line params// ww w. j av a 2s  .  c  o m
 */
public static void main(String[] args) { // CSIGNORE
    CSVReader csvReader = null;
    CSVWriter csvWriter = null;
    try {
        csvReader = new CSVReader(new BufferedReader(new FileReader(args[0])));
        csvWriter = new CSVWriter(new BufferedWriter(new FileWriter(args[1])));
        String[] line;
        Pattern pattern = Pattern.compile("^(\\w\\w\\w).*?(\\d+)(M|Y)(\\d+)(M|Y)\\s*?(PY|RC)\\s*?(.*)$");
        BloombergReferenceDataProvider rawBbgRefDataProvider = getBloombergSecurityFileLoader();
        MongoDBValueCachingReferenceDataProvider bbgRefDataProvider = MongoCachedReferenceData
                .makeMongoProvider(rawBbgRefDataProvider, BloombergSwaptionFileLoader.class);
        while ((line = csvReader.readNext()) != null) {
            String name = line[NAME_FIELD];
            Matcher matcher = pattern.matcher(name);
            if (matcher.matches()) {
                String ccy = matcher.group(1);
                String swapTenorSize = matcher.group(2);
                String swapTenorUnit = matcher.group(3);
                String optionTenorSize = matcher.group(4);
                String optionTenorUnit = matcher.group(5);
                String payReceive = matcher.group(6);
                String distanceATM = matcher.group(7);

                String buid = "/buid/" + line[BUID_FIELD];
                String value = bbgRefDataProvider.getReferenceDataValue(buid, "TICKER");
                csvWriter.writeNext(new String[] { name, ccy, swapTenorSize, swapTenorUnit, optionTenorSize,
                        optionTenorUnit, payReceive, distanceATM, value });
            } else {
                s_logger.error("Couldn't parse " + name + " field");
            }

        }
    } catch (IOException ioe) {
        s_logger.error("Error while reading file", ioe);
    } finally {
        IOUtils.closeQuietly(csvReader);
        IOUtils.closeQuietly(csvWriter);
    }
}

From source file:com.mmj.app.common.util.SpiderHtmlUtils.java

public static void main(String[] args) {
    Pattern pattern = Pattern.compile("[http|https]+[://]+[0-9A-Za-z:/[-]_#[?][=][.][&]]*");
    Matcher matcher = pattern.matcher("http://haitao.smzdm.com/youhui/307563");
    System.out.println(matcher.matches());
}

From source file:com.ariatemplates.seleniumjavarobot.Main.java

public static void main(String[] args) throws Exception {
    SeleniumJavaRobot seleniumJavaRobot = new SeleniumJavaRobot();
    String browser;/*from w  w  w. j av a  2  s.  c  o  m*/
    seleniumJavaRobot.autoRestart = false;
    if (OS.isFamilyMac()) {
        browser = "safari";
    } else {
        browser = "firefox";
    }
    seleniumJavaRobot.url = "http://localhost:7777/__attester__/slave.html";
    String usageString = String.format(
            "Usage: selenium-java-robot [options]\nOptions:\n  --auto-restart\n  --url <url> [default: %s]\n  --browser <browser> [default: %s, accepted values: %s]\n  -DpropertyName=value",
            seleniumJavaRobot.url, browser, BROWSERS_LIST.toString());
    for (int i = 0, l = args.length; i < l; i++) {
        String curParam = args[i];
        if ("--browser".equalsIgnoreCase(curParam) && i + 1 < l) {
            browser = args[i + 1];
            i++;
        } else if ("--url".equalsIgnoreCase(curParam) && i + 1 < l) {
            seleniumJavaRobot.url = args[i + 1];
            i++;
        } else if ("--auto-restart".equalsIgnoreCase(curParam)) {
            seleniumJavaRobot.autoRestart = true;
        } else if ("--version".equalsIgnoreCase(curParam)) {
            System.out.println(Main.class.getPackage().getImplementationVersion());
            return;
        } else if ("--help".equalsIgnoreCase(curParam)) {
            System.out.println(usageString);
            return;
        } else {
            Matcher matcher = SET_SYSTEM_PROPERTY_REGEXP.matcher(curParam);
            if (matcher.matches()) {
                System.setProperty(matcher.group(1), matcher.group(2));
            } else {
                System.err.println("Unknown command line option: " + curParam);
                System.err.println(usageString);
                return;
            }
        }
    }
    seleniumJavaRobot.robotizedBrowserFactory = LocalRobotizedBrowserFactory
            .createRobotizedWebDriverFactory(browser);
    seleniumJavaRobot.start();
    closeOnStreamEnd(seleniumJavaRobot, System.in);
    closeOnProcessEnd(seleniumJavaRobot);
}

From source file:MatcherMatchesExample.java

public static void main(String args[]) {
    Pattern p = Pattern.compile("J2SE");

    String candidateString_1 = "j2se";
    String candidateString_2 = "J2SE ";
    String candidateString_3 = "J2SE2s";

    Matcher matcher_1 = p.matcher(candidateString_1);
    Matcher matcher_2 = p.matcher(candidateString_2);
    Matcher matcher_3 = p.matcher(candidateString_3);

    String msg = ":" + candidateString_1 + ": matches?: ";
    System.out.println(msg + matcher_1.matches());

    msg = ":" + candidateString_2 + ": matches?: ";
    System.out.println(msg + matcher_2.matches());

    msg = ":" + candidateString_3 + ": matches?: ";
    System.out.println(msg + matcher_3.matches());

}

From source file:MainClass.java

public static void main(String args[]) {
    Pattern p = Pattern.compile("J2SE");

    String candidateString_1 = "j2se";
    String candidateString_2 = "J2SE ";
    String candidateString_3 = "J2SE";

    Matcher matcher_1 = p.matcher(candidateString_1);
    Matcher matcher_2 = p.matcher(candidateString_2);
    Matcher matcher_3 = p.matcher(candidateString_3);

    String msg = ":" + candidateString_1 + ": matches?: ";
    System.out.println(msg + matcher_1.matches());

    msg = ":" + candidateString_2 + ": matches?: ";
    System.out.println(msg + matcher_2.matches());

    msg = ":" + candidateString_3 + ": matches?: ";
    System.out.println(msg + matcher_3.matches());
}

From source file:com.payne.test.StringTest.java

public static void main(String[] args) throws IOException {
    //        String a = "160504185452148809-1";
    //        a = a.split("-")[0];
    //        System.out.println(a);
    //        Random r = new Random();
    //        long a = 0l;
    //        for(int i=0;i<10000;i++){
    //            a = r.nextInt(5001) + 5000;
    //            if(a==5000){
    //                System.out.println(a);
    //            }
    //        }/*from  w  ww. j  a v  a 2 s .  c o  m*/

    /**
     * ????
     */
    //        List<Integer> numberList = new ArrayList<>();
    //        numberList.add(1);
    //        numberList.add(2);
    //        Integer[] numbers = numberList.toArray(new Integer[numberList.size()]);
    ////        int[] numbers = new int[]{1,2};
    //        
    //        System.out.println(new Integer[]{}.length==0?0:1);
    //        
    //        Student s =  new Student();
    //        s.sumUp(new Integer[]{}.length==0?numbers:new Integer[]{1});
    //        s.sumUp(numbers);
    //        Parent p = null;
    //        Parent p2 = new Parent(new Student(5));
    //
    //        Student s = new Student();
    //        p = s.print(p);

    //        System.out.println(p==null?0:1);
    //        System.out.println(p.getAge());
    //        System.out.println(p.getStudent().getAge());
    //        int ai = 0;
    //        for(int i=0;i<2;i++){
    //            int b = 0;
    //            int b_grow = 0;
    //            for(int j=0;j<5;j++){
    //                b += new Random().nextInt(5);
    //            }
    //            
    //        }
    //        
    //        
    //        System.out.println(UUID.randomUUID().toString());

    //        int a = 1;
    //        a = doAdd(a);
    //        System.out.println(a);
    Pattern p = Pattern.compile("^\\d{1,9}(.\\d{1,2})?$");
    Matcher m = p.matcher("666666541.13");
    boolean b = m.matches();
    System.out.println(b);
    //          System.out.println(-2>>4);
    //        BigDecimal b = new BigDecimal(100.50);
    //        System.out.println(b.toString());
    // indexOf   ??
    //        String a = "?";
    //        
    //        String[] split = a.split("?");
    //        if(a.indexOf("?")>-1){
    //            System.out.println("111");
    //        }
    //        for(String s: split){
    //            System.out.println(s);
    //        }
    //        MapTestObject mto = new MapTestObject();
    //        mto.setOrderType(OrderType.TWO);
    //        
    //        String str = "\":\"";
    //        System.out.println(str);
    //        String a = ",";
    ////
    //        String[] splits = a.split(".");
    //        List<String> asList = Arrays.asList(splits);

    //        String last = "";
    //        String last = "";
    //        String last = "";
    //        if (!asList.isEmpty()) {
    //            if (asList.indexOf(last) > -1) {
    //                int indexOf = asList.indexOf(last);
    //                if (indexOf + 1 >= asList.size()) {
    //                    System.out.println("?");
    //                }else{
    //                    String next = asList.get(indexOf + 1);
    //                    if (OTHERStringUtils.isEmpty(next)) {
    //                        System.out.println("?");
    //                    } else {
    //                        System.out.println("?" + next);
    //                    }
    //                }
    //            } else {
    //                System.out.println("?");
    //            }
    //        } else {
    //            System.out.println("??");
    //        }

    //           System.out.println("?\",\""); 
    //           String a ="1123";
    //           a = StringUtils.substring(a, 0, a.length()-1);
    //           System.out.println("a="+a);
    //           
    int a = 0x12345678;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
    dos.writeInt(a);
    System.out.println(Integer.toHexString(a));
    byte[] c = baos.toByteArray();
    for (int i = 0; i < 4; i++) {
        System.out.println(Integer.toHexString(c[i]));
    }
}

From source file:com.movielabs.availstool.AvailsTool.java

public static void main(String[] args) throws Exception {
    String fileName, outFile, sheetName;
    int sheetNum = -1;

    Logger log = LogManager.getLogger(AvailsTool.class.getName());
    log.info("Initializing logger");

    Options options = new Options();
    options.addOption(Opts.v.name(), false, "verbose mode");
    options.addOption(Opts.s.name(), true, "specify sheet");
    options.addOption(Opts.f.name(), true, "specify file name");
    options.addOption(Opts.o.name(), true, "specify output file name");
    options.addOption(Opts.sstoxml.name(), false, "convert avails spreadsheet to XML");
    options.addOption(Opts.xmltoss.name(), false, "convert avails XML to a spreadsheet");
    options.addOption(Opts.dumpsheet.name(), false, "dump a single sheet from a spreadsheet");
    options.addOption(Opts.dumpss.name(), false, "dump a spreadsheet file");
    options.addOption(Opts.wx.name(), false, "treat warning as fatal error");
    options.addOption(Opts.clean.name(), false, "clean up data entries");

    CommandLineParser cli = new DefaultParser();

    try {/*from   ww w . ja  va 2s .c  om*/
        CommandLine cmd = cli.parse(options, args);
        boolean optToXML = cmd.hasOption(Opts.sstoxml.name());
        boolean optToSS = cmd.hasOption(Opts.xmltoss.name());
        boolean optDumpSS = cmd.hasOption(Opts.dumpss.name());
        boolean optDumpSheet = cmd.hasOption(Opts.dumpsheet.name());
        fileName = cmd.getOptionValue(Opts.f.name());
        sheetName = cmd.getOptionValue(Opts.s.name());
        boolean clean = cmd.hasOption(Opts.clean.name());
        boolean wx = cmd.hasOption(Opts.wx.name());
        boolean verbose = cmd.hasOption(Opts.v.name());
        AvailSS ss;
        AvailsSheet as;
        String message;

        if (sheetName != null) {
            Pattern pat = Pattern.compile("^\\d+$");
            Matcher m = pat.matcher(sheetName);
            if (m.matches())
                sheetNum = Integer.parseInt(sheetName);
        }

        if (fileName == null)
            throw new ParseException("input file not specified");

        if (!(optToXML | optToSS | optDumpSS | optDumpSheet))
            throw new ParseException("missing operation");

        if (optToXML) {
            if (optToSS | optDumpSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            outFile = cmd.getOptionValue(Opts.o.name());
            if (outFile == null)
                throw new ParseException("output file not specified");

            ss = new AvailSS(fileName, log, wx, clean);
            if (sheetNum < 0)
                as = ss.addSheet(sheetName);
            else
                as = ss.addSheet(sheetNum);
            message = "toXML file: " + fileName + " sheet: " + sheetName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            log.info("Options: -clean:" + clean + "; -wx:" + wx + "; output file: " + outFile);
            String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
            String shortDesc = String.format("generated XML from %s:%s on %s", fileName, sheetName, timeStamp);
            as.makeXMLFile(outFile, shortDesc);
        } else if (optToSS) {
            if (optToXML | optDumpSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            // TODO implement this
            outFile = cmd.getOptionValue(Opts.o.name());
            if (outFile == null)
                throw new ParseException("output file not specified");
            AvailXML x = new AvailXML(fileName, log);
            x.makeSS(outFile);
        } else if (optDumpSS) {
            if (optToXML | optToSS | optDumpSheet)
                throw new ParseException("more than one operation specified");
            message = "dumping file: " + fileName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            AvailSS.dumpFile(fileName);
        } else { // dumpSheet
            if (sheetName == null)
                throw new ParseException("sheet name not specified");
            message = "dumping file: " + fileName + " sheet: " + sheetName;
            log.info(message);
            if (verbose)
                System.out.println(message);
            ss = new AvailSS(fileName, log, wx, clean);
            if (sheetNum < 0)
                as = ss.addSheet(sheetName);
            else
                as = ss.addSheet(sheetNum);

            ss.dumpSheet(sheetName);
        }
    } catch (ParseException exp) {
        System.out.println("bad command line: " + exp.getMessage());
        usage();
        System.exit(-1);
    }
}

From source file:core.plugin.mybatis.PageInterceptor.java

public static void main(String[] args) {
    List<String> tests = new ArrayList<String>();
    tests.add("select count(*) from abc \n\t\t where\n abc");
    tests.add("SELECT COUNT(*) from abc");
    tests.add(" select count (*) from abc");
    tests.add(" select count( *) from abc");
    tests.add("select count( * ),id from abc");
    tests.add("select * from abc");
    tests.add("select abc,test,fdas from abc");
    tests.add("select count(adb) from abc");
    tests.add("select count(0) from abc");
    tests.add("select min(count(*)) from abc");
    tests.add("update min(count(*)) from abc");
    tests.add("delete min(count(*)) from abc");
    Pattern p1 = Pattern.compile(SQL_SELECT_REGEX, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    Pattern p2 = Pattern.compile(SQL_COUNT_REGEX, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
    for (String str : tests) {
        Matcher m1 = p1.matcher(str);
        Matcher m2 = p2.matcher(str);
        System.out.println("?: " + str);
        System.out.println(" select?? " + m1.matches());
        System.out.println(" count?? " + m2.matches());
        System.out.println();/*from  w w  w .  ja va2s. co  m*/
    }
}